PDA

View Full Version : Floating point identification how is it done? last bit ?

Zap-o
07-23-2009, 04:37 AM
Is there a specific way that I can check a bit in a variable to tell if it is in floating point form.

For example:

I have some data entered into a variable and before I manipulate it and use the "math.Fadd" function I need to know beforehand to float it or leave it.

IF varable is not a floating point
math.Ffloat this variable
else
math.Ffloat(variable, 1.02)

Any help is appreciated.

Post Edited (Zap-o) : 7/22/2009 10:07:38 PM GMT

Nick Mueller
07-23-2009, 05:11 AM
No, no way.

Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:

Zap-o
07-23-2009, 05:51 AM
What do you mean no way? Is it not true that only 27 bits are used in floating point? The other 4 are used for something.

07-23-2009, 05:54 AM
Zap-o said...
What do you mean no way? Is it not true that only 27 bits are used in floating point? The other 4 are used for something.

The entire 32 bits are used to represent the FP number. There is no way to determine if it's signed/unsigned/fp...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<This space for rent>

Phil Pilgrim (PhiPi)
07-23-2009, 05:55 AM
All 32 bits are used for both floating point and integers. There's no way to tell from the value how that value was created.

-Phil

Bobb Fwed
07-23-2009, 05:58 AM
I think this is the right reference to use: en.wikipedia.org/wiki/Single_precision_floating-point_format (http://en.wikipedia.org/wiki/Single_precision_floating-point_format) or en.wikipedia.org/wiki/IEEE_754-2008 (http://en.wikipedia.org/wiki/IEEE_754-2008)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!

David B
07-23-2009, 06:43 AM
Given some "random" 32 bit variable, I think all you could do is check whether it might not be a float, as there are some bit patterns that aren't valid floating points, referred to as "NAN" for "not a number" values.

But apart from that, any random number could be a valid float number, even if it wasn't intended to be.

If you really need this functionality, maybe you could set up a separate array of flag bits to track the status of your numbers; whether they have been converted to float or not.

Phil Pilgrim (PhiPi)
07-23-2009, 07:57 AM
The flag array might not be a bad idea if you need dynamic typing of VARS. There are 8192 longs in hub RAM. Assigning each one a flag bit would require 1024 bytes. For non-graphics apps, that's not a show-stopper. It would not work for method-local variables, though, since they do not have static addresses.

-Phil

Nick Mueller
07-23-2009, 10:41 PM
> as there are some bit patterns that aren't valid floating points, referred to as "NAN" for "not a number" values.

Even these are valid and very useful values!

Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.: