Home AMX User Forum AMX General Discussion

+ and - floating point numbers

I am doing some temperature conversion and I need to eliminate the rounding errors in a formula. I decided to go with Floating point math as opposed to (1000(x))/1000 because I flipped a coin and floating won :) Anyway, I added the .0 to the end of all my numbers and hit the compile button. I was a little surprised when I got an error message (especially when it was as helpful as: Syntax Error; Illegal or invalid syntax in code. :) ). The only thing I changed was adding the .0 since the last successful compile.

I pulled the .0 back out and everything compiled fine. A little progressive addition of code led me to the following:

tempTemp = (((tempTemp/2.0)*9.0)/5.0+32.0); = BAD

tempTemp = (((tempTemp/2.0)*9.0)/5.0+ 32.0); = GOOD

For some reason, addition and subtraction need a space between the number and the operator. I am sure this has to do with the number being treated as a signed value.

Just a little FYI. Not sure what other problems might be introduced if the compiler attempted to figure this out on its own, so I am fine with adding a space for this (as I don't use it but once every couple years :) )

Jeff

Comments

  • a_riot42a_riot42 Posts: 1,624
    Spire_Jeff wrote: »

    tempTemp = (((tempTemp/2.0)*9.0)/5.0+32.0); = BAD

    tempTemp = (((tempTemp/2.0)*9.0)/5.0+ 32.0); = GOOD

    Weird, but those magic numbers should be constants anyway. Try making them constants and see if you still get a compilation error.
    Paul
Sign In or Register to comment.