Dr Scheme question: Float to integer conversion? 
Author Message
 Dr Scheme question: Float to integer conversion?

How do you convert a float to an integer? Example: 1.0 -> 1

I need to know since my algorithm involves take a min of list of numbers, if
that list includes any floats than the return type will be float.

Example: (min 1 2.3 5 5) returns 1.0

I do a check later with member which looks for that return value (1.0) in the
same list (1 2.3 5), it will return #f since 1 is not equal to 1.0 from the
interpreters point of view. THanks for any help!



Mon, 04 Aug 2003 04:45:19 GMT  
 Dr Scheme question: Float to integer conversion?

Quote:
>How do you convert a float to an integer? Example: 1.0 -> 1
>I need to know since my algorithm involves take a min of list of numbers, if
>that list includes any floats than the return type will be float.
>Example: (min 1 2.3 5 5) returns 1.0
>I do a check later with member which looks for that return value
>(1.0) in the same list (1 2.3 5), it will return #f since 1 is not
>equal to 1.0 from the interpreters point of view. THanks for any
>help!

The Scheme procedure 'inexact->exact' should do what you want:

        (inexact->exact 1.0) ==> 1

Cheers,
-M

--
Michael J. Fromberger    Software Engineer, Thayer School of Engineering
  sting <at> linguist.dartmouth.edu   http://www.dartmouth.edu/~sting/



Mon, 04 Aug 2003 11:26:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Float, integer conversions

2. integer to 32-bit float conversion

3. Slow floating point to integer conversion in VC++ -- Pentium Pro/II

4. Float to Integer Conversion ?

5. HELP: Fast Integer to Floating-Point Conversion on a Pentium

6. Integer/floating point type conversion in Prolog

7. Float/Short Float Conversion

8. Conversion question (HOW TO convert to integer from STD_LOGIC_VECTOR)

9. newbie question: String to Integer conversion

10. Newbie Question - Hex to floating point conversion

11. string to integer conversion question

12. Newbie to Dr Scheme programming question

 

 
Powered by phpBB® Forum Software