flat assembler
Message board for the users of flat assembler.
Index
> Main > Yet another floating point thread... |
Author |
|
edfed 05 Dec 2009, 08:33
maybe a better way would be convert fpu value directlly in long integer
for example, a 64 bit value, 32 for the int part, 32 for the frac part. for this, you should store integer part, sub integer multiply the rest by 2^32 store as integer. ptr => str do the num2str convertion of int part put '.' char at ptr, inc ptr do the num2str convertion of frac part print str |
|||
05 Dec 2009, 08:33 |
|
kohlrak 05 Dec 2009, 08:43
That's basically what i'm doing, no? I'm using fist to get the left part, i'm then printing it (but not before preserving it and the floating point registers). Then i throw the preserved st0 back in, subtract the int part from it, multiply what's left by 1 and eight 0s for 8 places of precision, then i fist that part to print it out.
|
|||
05 Dec 2009, 08:43 |
|
edfed 05 Dec 2009, 09:01
excuze me, i didn't understood the code you wrote. i am noob in fpu. |
|||
05 Dec 2009, 09:01 |
|
kohlrak 05 Dec 2009, 09:10
It's ok, the FPU is a horrible device, and i made sure the reader knew that too. The only thing worse than the device itself is the format of floating point numbers which produces amazing results so people who aren't as knowledgeable tend to trust them more than they should. Can you imagine how many stupid scientific theories there may be out there that exist all because the accuracy is "good enough" when applied to models? Once you have an error due to the representation of the number in floating point format (whole numbers are notoriously strange) the errors just keep increasing and increasing.
I remember one time when taking VB last year that I spent a week or two arguing with the teacher about why my output would either match the book's sample or the output generated by the running program that came with the book. Needless to say, the argument finally ended when he did what i told him and checked the output in the book to see if the program he was running came up with the same numbers. Considering all i had to do to get my program to match one or the other was to switch from "float" to "double" and back, the outputs didn't match and i once again managed to get him to shut up when it came to problems we students were having. He notoriously seeks perfection and blames his students when they find that the book and/or test programs provided with it don't work. I still remember arguing with him that 10/2 is 5, not 8... |
|||
05 Dec 2009, 09:10 |
|
Borsuc 05 Dec 2009, 17:06
What's your code supposed to do? Extract the mantissa & exponent? Sorry, I don't get it.
|
|||
05 Dec 2009, 17:06 |
|
windwakr 05 Dec 2009, 18:28
Borsuc wrote: What's your code supposed to do? Extract the mantissa & exponent? Sorry, I don't get it. He extracts the whole and fractional part of the number and prints them. He makes a backup and stores the thing as an integer, then prints that. Then he prints a "." and subtracts the integer part off the backup, multiplies that by 100,000,000, and prints that. Kohlrak, I recommend that you change the rounding to truncate so rounding doesn't mess you up. With the default rounding, you will end up with the first digit after the decimal point wrong. And if it rounded up, the thing would be COMPLETELY wrong. http://www.website.masmforum.com/tutorials/fptute/fpuchap1.htm#cword http://www.website.masmforum.com/tutorials/fptute/fpuchap3.htm#fstcw http://www.website.masmforum.com/tutorials/fptute/fpuchap3.htm#fldcw Something like this(I put comments on what I added): Code: printfpubuffer dd 0 printfpupreserve dd 0 printfpudot db '.', 0 printfpucw dw 0 ;Holder for the Control Word printfpu: fstcw [printfpucw] ;Store Control Word or [printfpucw],0000110000000000 ;Enable Truncate fldcw [printfpucw] ;Load Control Word to the FPU fst dword [printfpupreserve] fist dword [printfpubuffer] printnum dword [printfpubuffer] printtext printfpudot fninit ;resets the Control Word, which is fine. You only needed it for the fist. fld dword [printfpupreserve] fisub dword [printfpubuffer] mov dword [printfpubuffer], 100000000 fimul dword [printfpubuffer] fist dword [printfpubuffer] printnum dword [printfpubuffer] ret Last edited by windwakr on 05 Dec 2009, 20:28; edited 1 time in total |
|||
05 Dec 2009, 18:28 |
|
Borsuc 05 Dec 2009, 20:08
oh I thought he wanted to display it in scientific notation, sorry.
|
|||
05 Dec 2009, 20:08 |
|
kohlrak 05 Dec 2009, 23:31
Odd, i thought the FIs truncated, and you had to frndint to get anything else. If that's the case, all i have to do is fabs and the result is good, and just add a comment about rounding mode. Thanks for your help, all.
Edit: what was i thinking? fld1, some sort of fcompare, and fadd. That way, the reader doesn't have to look up the uglyness of the FPU, just a handful of instructions. Plus, shouldn't the fninit to be used to prevent the fpu from flipping out if it somehow gets overflowed or mmx is used behind the scenes? (Since we dont' know what printf does.) Edit: I shouldn't code or make comments shortly after waking up... Looks like i'll have to do that, despite how much i don't want to. |
|||
05 Dec 2009, 23:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.