flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > Float 16bit?

Author
Thread Post new topic Reply to topic
d0z



Joined: 11 Oct 2005
Posts: 11
Location: Sweden
I'm trying to use float in 16bit environment. But I can't figure out how to declare an single precision float.

This is what I'm trying to do.
Code:
Sin dd 0.173648f   ;Sin 10 degrees
mov ax,word [Sin]
mov dx,word [Sin+2]
    


The result is: dx:ax = 1|11110001|100011101000011001000 = Very large negative number.

[edit]
Are all declared float treated as double precision?
[/edit]
Post 24 Oct 2005, 13:34
View user's profile Send private message Reply with quote
d0z



Joined: 11 Oct 2005
Posts: 11
Location: Sweden
Hehe, if you read my previous post you can atleast see one error in it. I'm trying to represent a double word with 30bits. Smile
What I have learned from this is to never trust Microsoft's calculator as it cuts of ending zeros. The bits should look like this:

0|01111100|01100011101000011001000

If I have understood floating numbers this is how it works. Lets say we have bit 0 to the right and bit 31 to the left.
Bit31 = 1 if negative otherwise 0
Bit23-30 = Exponent
Bit0-22(23) = Mantissa

Bit23 is a very special bit since it being assumed to be 1 when used together with mantissa even if it is 0 in my example above. It is only assumed to be 0 in special cases. The mantissa is represented like this when you calculate it:
1.01100011101000011001000
2^0+0^-1+2^-2...+0^-23
If you want to make it easy on yourself you put everything after the dot in a calculator converts it to decimal and divide it by 2^23 and then add 1.

Conclusion:
What I tried to represent as a dw was 0.173648 if you do the calculation from my bits above you get. 1*2^(124-127)*1.389183=0.1736478. So it seems my previous code was right and Fasm handles my Sin value as single precision.

If you would like to know more about float go here http://stevehollasch.com/cgindex/coding/ieeefloat.html

Hopefully this helps some confused float newbies as myself.
Post 24 Oct 2005, 20:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.