Shop OBEX P1 Docs P2 Docs Learn Events
Floating point identification how is it done? last bit ? — Parallax Forums

Floating point identification how is it done? last bit ?

Zap-oZap-o Posts: 452
edited 2009-07-23 15:41 in Propeller 1
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

Comments

  • Nick MuellerNick Mueller Posts: 815
    edited 2009-07-22 22:11
    No, no way.

    Nick

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

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Zap-oZap-o Posts: 452
    edited 2009-07-22 22:51
    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.
  • BradCBradC Posts: 2,601
    edited 2009-07-22 22:54
    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)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-22 22:55
    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 FwedBobb Fwed Posts: 1,119
    edited 2009-07-22 22:58
    I think this is the right reference to use: en.wikipedia.org/wiki/Single_precision_floating-point_format or en.wikipedia.org/wiki/IEEE_754-2008

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!
  • David BDavid B Posts: 592
    edited 2009-07-22 23:43
    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)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-23 00:57
    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 MuellerNick Mueller Posts: 815
    edited 2009-07-23 15:41
    > 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.:
    YADRO
Sign In or Register to comment.