PDA

View Full Version : Float to Integer Numeric Conversion


Jawahar
10-15-04, 10:26 AM
I am trying to convert a floating type number to an integer type. For example, I have 33.33E0. I want just 33 (the integer part of it). How would I do this in IsoMax?

Thanks.

P.S.
I want "single-precision" integer values

RMDumse
10-15-04, 10:37 AM
Well, the simple way, you could do a F>D (Float to Double) and then make the double into a single by dropping the top half of the double.

The danger there is if the float value is outside the range of the single you'll get "part" of a number.

Here's a way that first limits the float to fit in a single, then uses basically the same scheme:

: F>S 32767.0E0 FMIN -32768.0E0 FMAX F>D DROP ; EEWORD ( MAKE FLOAT SINGLE

Jawahar
10-15-04, 10:46 AM
Thanks!

The range of operation is well within -32767 to + 32767. So I guess it should work. I 'll get back after trying it out.