![]() |
fixed is broken (*solved*) - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15) +---- Thread: fixed is broken (*solved*) (/showthread.php?tid=333) |
fixed is broken (*solved*) - britlion - 03-17-2011 Code: CLS The last line - ln(num) breaks it. Without that line it compiles, but gives nonsensical answers. I think this is the reason why my fSin benchmark isn't compiling. fSin works with fixed point numbers. There's an issue with input / strings as well though: Code: CLS Compiles, but gave an out of screen error for me. Re: fixed is broken - britlion - 03-17-2011 Oh, just saw your reply to the speed trial: fSin is in the library at <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:FSin.bas">http://www.boriel.com/wiki/en/index.php ... C:FSin.bas</a><!-- m --> Code I'm using: Code: #include "fSin.bas" For the three trials I comment /uncomment Bm7 and 8 start points and comment out the BM8 code if I'm doing BM7, and change the Sin into fSin if necessary and run. That's all I changed. Re: fixed is broken - boriel - 03-18-2011 This is related to the completely rewritten backend compiler module (1.2.7 undergone an entire new preprocessor which now allows function inlining -using complex macros with parameter substitution). Now it's time to fix backend when I realised the bug I introduced in 1.2.6 :oops: This means I have to re-check almost every expression case in every context for every type (array, assignation, evaluation, etc for UByte, Byte, Uinteger, Integer, Ulong, Long, Fixed, Float, String) :oops: Currently I've finished both 8 & 16 bits types (and probably strings). Because they're used most frequently. ![]()
PS: I think fsin.bas should be renamed to fmath.bas since it contains many math functions (even sqrt?). It you think it's ready it can be packaged with the compiler from now on. Re: fixed is broken - britlion - 03-18-2011 boriel Wrote:This is related to the completely rewritten backend compiler module (1.2.7 undergone an entire new preprocessor which now allows function inlining -using complex macros with parameter substitution). Now it's time to fix backend when I realised the bug I introduced in 1.2.6 :oops: This means I have to re-check almost every expression case in every context for every type (array, assignation, evaluation, etc for UByte, Byte, Uinteger, Integer, Ulong, Long, Fixed, Float, String) :oops: Oh dear. ![]() boriel Wrote:PS: I think fsin.bas should be renamed to fmath.bas since it contains many math functions (even sqrt?). It you think it's ready it can be packaged with the compiler from now on. Um, no? fSin only does Sine functions, as a fast and rougher (less accurate) calculation as written there. I have fcos.bas and ftan.bas as separate files, though they do call fSin. I suppose we could package them all up as fTrig. There's are two square root functions in the library; fSqrt, which uses the FP calculator to calculate square roots six times faster than the rom code, with full decimal accuracy. I still think that's small enough you might want to default to it if someone uses square roots. iSqrt does integer square roots - so iSqrt(10) comes back as 3 - it basically loses the decimal in the answer. It's about 100X faster than the ROM code for 16 bit numbers, and 50X faster for 32 bit numbers; and given how slow the ROM code is, it can be quite a big difference. If anyone is ever thinking of doing anything like 3d/2d vector graphics, these two will come in very useful. The maths functions in the library seem solid, apart from issues with the fixed point type. Please see <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m --> for details. Re: fixed is broken - boriel - 03-18-2011 Well at this moment the best help is... testing, testing, TESTING :twisted: Currently there are 100+ test cases created. So everytime a fix is introduced, a new test is created. Later the compiler is run against all those test and must pass all of them. So... at first it means much work, but in the end it's worth the hassle ![]() Regardless to FP (not fixed) arithmetic, I'm thinking in introducing a flag I've seen in gcc and other compilers: --fast-floating-point or --ffast-math so it will use it's own floating point routines for +,-,*,/,SIN,COS,SQRT etc... What do you think? I'm also glad to see even GCC has it's own bugs (similar to ZX BASIC :!: ) and their own regression test <!-- m --><a class="postlink" href="http://bit.ly/hAqYxc">http://bit.ly/hAqYxc</a><!-- m --> I guess this is a common problem in compiler design. When ZX Basic reach a minimun quality I will open it to public contribution so people cna contribute to the code directly. :roll: Re: fixed is broken - boriel - 03-19-2011 Okay: Download current latest version 1.2.8-s644. This is a half fix for ALL remaining types (Float, Fixed, Ulong, Long); Integer, Uinteger, Byte and Ubyte were already fixed. There are still pending fixed. Please be patient and expect some errors (e.g. the fsin _identifier error should still remain), but calculations and prints should print accurate results now. I'm also puzzled with the benchmark result you have published as it seems 1.2.6 performing better, but this also might be bug-related. Please run your (very) interesting benchmark and update the thread... ? maybe there is some improvement... Update: Just re-uploaded the revision s644 and should have this error fixed... Please, check and tell me :roll: Re: fixed is broken - britlion - 03-19-2011 s644 does indeed fix the issue - the benchmark now compiles correctly with fSin included. Well found, Boriel! I posted the speed, though. 1.26 does still seem to be 40% faster generally. Re: fixed is broken - boriel - 03-19-2011 Ok. This bug is closed. Let's discuss the benchmark and performance issues in the related thread! 8) |