Next: , Previous: , Up: Top   [Index]

## 13 Formatting flonums

The following bindings are exported by the library (vicare numerics flonum-formatter).

Function: format-flonum positive? digits exponent

Given a list of characters digits and a fixnum exponent compose a string representing the corresponding flonum. positive? determines the sign.

#!r6rs
(import (vicare)
(vicare numerics flonum-formatter))

(define digits
'(#\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9))

(format-flonum #t digits 0)     ⇒ "0.123456789"
(format-flonum #t digits 1)     ⇒ "1.23456789"
(format-flonum #t digits 2)     ⇒ "12.3456789"
(format-flonum #t digits 3)     ⇒ "123.456789"
(format-flonum #t digits 8)     ⇒ "12345678.9"
(format-flonum #t digits 9)     ⇒ "123456789.0"
(format-flonum #t digits 10)    ⇒ "1.23456789e9"

(format-flonum #t digits -1)    ⇒ "0.0123456789"
(format-flonum #t digits -2)    ⇒ "0.00123456789"
(format-flonum #t digits -3)    ⇒ "0.000123456789"
(format-flonum #t digits -4)    ⇒ "1.23456789e-5"

(format-flonum #f digits 1)     ⇒ "-1.23456789"
(format-flonum #f digits 2)     ⇒ "-12.3456789"
(format-flonum #f digits 3)     ⇒ "-123.456789"
(format-flonum #f digits 8)     ⇒ "-12345678.9"
(format-flonum #f digits 9)     ⇒ "-123456789.0"
(format-flonum #f digits 10)    ⇒ "-1.23456789e9"

(format-flonum #f digits -1)    ⇒ "-0.0123456789"
(format-flonum #f digits -2)    ⇒ "-0.00123456789"
(format-flonum #f digits -3)    ⇒ "-0.000123456789"
(format-flonum #f digits -4)    ⇒ "-1.23456789e-5"