Home AMX User Forum AMX General Discussion
Options

Ieee 754

Someone could tell me how can I convert a float to IEEE 754 format number, thanks.

Comments

  • Options
    jweatherjweather Posts: 320
    Your float is probably already a IEEE 754 number. IEEE 754 covers the binary representation, which is not something you can get at in NetLinx as far as I know. I don't know details about AMX's floating point processor, but I assume it's similar to x86 and all the other FP processors for the last decade or so.

    Which brings up the question... why do you care about the representation? Please don't tell me you've found a device that wants a binary representation of a IEEE 754 float in its control protocol...

    Jeremy
  • Options
    NMarkRobertsNMarkRoberts Posts: 455
    jweather wrote:
    Your float is probably already a IEEE 754 number.

    That got me thinking "but you can't get to it" (meaning that you can only do arithmetic and ASCII conversions with floats) so I did an experiment. The only method I could think of that might work was type_cast to a string but it just throws a "GetString error 1".
  • Options
    jweatherjweather Posts: 320
    Thus a fundamental difference between NetLinx and C. C will let you do something silly like:
    float f = 3.14;
    int x;
    
    x = *((int *) &f);
    printf("%x", x);
    

    ...because typecasting a pointer in C means "get out of my way and let me shoot myself in the foot", where normal typecasts (in C and NetLinx) actually try to make a sane conversion.

    Jeremy
Sign In or Register to comment.