Module (chicken flonum)
Because CHICKEN supports a full numeric tower, operations can sometimes incur a subtantial overhead to simply detect the type of numbers you're passing in. When you know you're definitely dealing only with flonums, you can choose to use flonum-specific operations to avoid this overhead.
This is purely a performance hack. You might want to consider adding type annotations instead, this often gives the same performance boost without having to rewrite all numeric operators in your code.
Arithmetic floating-point operations
[procedure] (fp+ X Y)[procedure] (fp- X Y)
[procedure] (fp* X Y)
[procedure] (fp/ X Y)
[procedure] (fp*+ X Y Z)
[procedure] (fpgcd X Y)
[procedure] (fpneg X)
[procedure] (fpmin X Y)
[procedure] (fpmax X Y)
[procedure] (fp= X Y)
[procedure] (fp> X Y)
[procedure] (fp< X Y)
[procedure] (fp>= X Y)
[procedure] (fp<= X Y)
[procedure] (fpfloor X)
[procedure] (fpceiling X)
[procedure] (fptruncate X)
[procedure] (fpround X)
[procedure] (fpsin X)
[procedure] (fpcos X)
[procedure] (fptan X)
[procedure] (fpasin X)
[procedure] (fpacos X)
[procedure] (fpatan X)
[procedure] (fpatan2 X Y)
[procedure] (fpsinh X)
[procedure] (fpcosh X)
[procedure] (fptanh X)
[procedure] (fpasinh X)
[procedure] (fpacosh X)
[procedure] (fpatanh X)
[procedure] (fplog X)
[procedure] (fpexp X)
[procedure] (fpexpt X Y)
[procedure] (fpsqrt X)
[procedure] (fpabs X)
[procedure] (fpinteger? X)
Arithmetic floating-point operations.
In safe mode, these procedures throw a type error when given non-float arguments. In unsafe mode, these procedures do not check their arguments. A non-flonum argument in unsafe mode can crash the application. fp*+ implements fused multiply-add (X * Y) + Z.
Note: fpround uses the rounding mode that your C library implements, which is usually different from R5RS.
Flonum limits
[constant] maximum-flonum[constant] minimum-flonum
[constant] flonum-radix
[constant] flonum-epsilon
[constant] flonum-precision
[constant] flonum-decimal-precision
[constant] flonum-maximum-exponent
[constant] flonum-minimum-exponent
[constant] flonum-maximum-decimal-exponent
[constant] flonum-minimum-decimal-exponent
Platform-specific flonum limits.
[procedure] (flonum-print-precision [PRECISION])Gets and sets the number of significant digits printed for a floating-point number. PRECISION must be a positive fixnum. Returns the setting that was previously in effect.
The default print precision is 15 on nearly all systems, and 7 on the rare system on which the double type is only single-precision.
Note: To ensure read/write invariance for all floating-point numbers, you must increase print precision from 15 to 17 (or from 7 to 9). For example:
> (define a (expt 2 -53)) > (define b (+ a (* 2 (expt 10 -32)))) > (eqv? a b) #f > (flonum-print-precision 15) > (cons a b) (1.11022302462516e-16 . 1.11022302462516e-16) ;; same printed representation > (flonum-print-precision 17) > (cons a b) (1.1102230246251565e-16 . 1.1102230246251568e-16) ;; differs in last place
On the downside, this will result in unnecessarily precise representations of many numbers:
> (flonum-print-precision 17) > 0.1 0.10000000000000001
The maximum number of decimal digits required to uniquely represent all floating-point numbers of a certain precision is given by the formula ceil(1+N*log10(2)), where N is the number of bits of precision; for double-precision, N=53.
Previous: Module (chicken fixnum)
Next: Module (chicken foreign)