This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Float syntax


* Jamison Hope [2011-01-10 16:26] writes:

> On Jan 9, 2011, at 3:40 AM, Helmut Eller wrote:
>
>> Is there a syntax for Float.POSITIVE_INFINITY or
>> Double.POSITIVE_INFINITY?  Or is that somehow the same as +inf.0?
>
> You can always use java.lang.Float:POSITIVE_INFINITY or
> java.lang.Double:POSITIVE_INFINITY,
> but +inf.0 will automagically get converted to a double or float when
> the situation requires.

I'm reading the float value as s-expr from a file, so this doesn't work
in my case.  I ended up using a the symbol 'positive-infinity and handle
that in the parsing code.

> You can also explicitly cast it if you want.
>
> #|kawa:1|# +inf.0
> +inf.0
> #|kawa:2|# (float? +inf.0)
> #f
> #|kawa:3|# (double? +inf.0)
> #f
> #|kawa:4|# (*:getClass +inf.0)
> class gnu.math.DFloNum
> #|kawa:5|# (float? (as float +inf.0))
> #t
> #|kawa:6|# (double? (as double +inf.0))
> #t
> #|kawa:7|# java.lang.Float:POSITIVE_INFINITY
> Infinity
> #|kawa:8|# (as float +inf.0)
> Infinity
> #|kawa:9|# (define (is-float-infinity? (f ::float)) ::boolean (or (= f
> java.lang.Float:POSITIVE_INFINITY) (= f
> java.lang.Float:NEGATIVE_INFINITY)))
> #|kawa:10|# (is-float-infinity? +inf.0)
> #t
> #|kawa:11|# (is-float-infinity? -inf.0)
> #t
> #|kawa:12|# (gnu.math.DFloNum:asDFloNumOrNull
> java.lang.Float:POSITIVE_INFINITY)
> +inf.0

Some fun facts about floats:

(= 0.0s0 0.0s0) => #t
(eqv? 0.0s0 0.0s0) => #f
(equal? 0.0s0 0.0s0) => #t
(= 0.0s0 0.0d0) => #t
(eqv? 0.0s0 0.0d0) => #f
(equal? 0.0s0 0.0d0) => #f
(= java.lang.Double:POSITIVE_INFINITY 
   java.lang.Float:POSITIVE_INFINITY) => #t
(equal? java.lang.Double:POSITIVE_INFINITY 
        java.lang.Float:POSITIVE_INFINITY) => #f

Helmut


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]