;;;; Conversions between the unsigned integers and the floats, across the top ;;;; half of u64's range, where the value does not fit a signed register. Both ;;;; backends print the same lines. Each case is written twice: once through a ;;;; global, so the conversion happens at run time, and once on a literal. ;;;; ;;;; A float is printed by converting it back to an integer, because the ;;;; printed float has six digits and every case here differs past the sixth. (defonce top u64 18446744073709551615) ; 2^64 - 1 (defonce half1 u64 9223372036854775809) ; 2^63 + 1 (defonce tie0 u64 9223372036854776832) ; 2^63 + 1024, a tie that rounds down to even (defonce tie1 u64 9223372036854778880) ; 2^63 + 3072, a tie that rounds up to even (defonce above u64 9223372036854776833) ; 2^63 + 1025, just past a tie (defonce small u64 12345) (defonce ftie0 u64 9223372586610589696) ; 2^63 + 2^39, an f32 tie that rounds down (defonce fup u64 9223372586610589697) ; 2^63 + 2^39 + 1 (defonce ftie1 u64 9223373686122217472) ; 2^63 + 3*2^39, an f32 tie that rounds up (defonce u32top u32 4294967295) (defonce d63 f64 9223372036854775808.0) ; 2^63 (defonce dmax f64 18446744073709549568.0) ; the largest f64 below 2^64 (defonce dbelow f64 9223372036854774784.0) ; the largest f64 below 2^63 (defonce d15 f64 1.5e19) (defonce dsmall f64 7.9) (defonce s63 f32 9223372036854775808.0) (defonce smax f32 18446742974197923840.0) ; the largest f32 below 2^64 (defonce d32 f64 4294967295.0) (defonce d3e9 f64 3e9) (defn main [] i32 ;; u64 to f64. (println (f64 top)) (println (u64 (* (f64 top) 0.5))) (println (u64 (f64 half1))) (println (u64 (f64 tie0))) (println (u64 (f64 tie1))) (println (u64 (f64 above))) (println (u64 (f64 small))) (println (f64 (u64 18446744073709551615))) (println (u64 (f64 (u64 9223372036854778880)))) ;; u64 to f32. (println (u64 (* (f32 top) (f32 0.5)))) (println (u64 (f32 ftie0))) (println (u64 (f32 fup))) (println (u64 (f32 ftie1))) (println (u64 (f32 small))) (println (u64 (f32 (u64 9223372586610589697)))) ;; u32 to both. (println (u64 (f64 u32top))) (println (u64 (f32 u32top))) ;; f64 and f32 to u64. (println (u64 d63)) (println (u64 dmax)) (println (u64 dbelow)) (println (u64 d15)) (println (u64 dsmall)) (println (u64 s63)) (println (u64 smax)) (println (u64 18446744073709549568.0)) (println (u64 (f32 1.5e19))) ;; f64 to u32. (println (u32 d32)) (println (u32 d3e9)) (println (u32 4294967295.0)) 0)