#lang scribble/doc @(require "mz.rkt" (for-label racket/flonum)) @(define fl-eval (make-base-eval)) @examples[#:hidden #:eval fl-eval (require racket/flonum)] @title[#:tag "flonums"]{Flonums} @defmodule[racket/flonum] The @racketmodname[racket/flonum] library provides operations like @racket[fl+] that consume and produce only @tech{flonums}. Flonum-specific operations can provide better performance when used consistently, and they are as safe as generic operations like @racket[+]. @guidealso["fixnums+flonums"] @; ------------------------------------------------------------------------ @section{Flonum Arithmetic} @deftogether[( @defproc[(fl+ [a flonum?] [b flonum?]) flonum?] @defproc[(fl- [a flonum?] [b flonum?]) flonum?] @defproc[(fl* [a flonum?] [b flonum?]) flonum?] @defproc[(fl/ [a flonum?] [b flonum?]) flonum?] @defproc[(flabs [a flonum?]) flonum?] )]{ Like @racket[+], @racket[-], @racket[*], @racket[/], and @racket[abs], but constrained to consume @tech{flonums}. The result is always a @tech{flonum}.} @deftogether[( @defproc[(fl= [a flonum?] [b flonum?]) boolean?] @defproc[(fl< [a flonum?] [b flonum?]) boolean?] @defproc[(fl> [a flonum?] [b flonum?]) boolean?] @defproc[(fl<= [a flonum?] [b flonum?]) boolean?] @defproc[(fl>= [a flonum?] [b flonum?]) boolean?] @defproc[(flmin [a flonum?] [b flonum?]) flonum?] @defproc[(flmax [a flonum?] [b flonum?]) flonum?] )]{ Like @racket[=], @racket[<], @racket[>], @racket[<=], @racket[>=], @racket[min], and @racket[max], but constrained to consume @tech{flonums}.} @deftogether[( @defproc[(flround [a flonum?]) flonum?] @defproc[(flfloor [a flonum?]) flonum?] @defproc[(flceiling [a flonum?]) flonum?] @defproc[(fltruncate [a flonum?]) flonum?] )]{ Like @racket[round], @racket[floor], @racket[ceiling], and @racket[truncate], but constrained to consume @tech{flonums}.} @deftogether[( @defproc[(flsin [a flonum?]) flonum?] @defproc[(flcos [a flonum?]) flonum?] @defproc[(fltan [a flonum?]) flonum?] @defproc[(flasin [a flonum?]) flonum?] @defproc[(flacos [a flonum?]) flonum?] @defproc[(flatan [a flonum?]) flonum?] @defproc[(fllog [a flonum?]) flonum?] @defproc[(flexp [a flonum?]) flonum?] @defproc[(flsqrt [a flonum?]) flonum?] )]{ Like @racket[sin], @racket[cos], @racket[tan], @racket[asin], @racket[acos], @racket[atan], @racket[log], @racket[exp], and @racket[sqrt], but constrained to consume and produce @tech{flonums}. The result is @racket[+nan.0] when a number outside the range @racket[-1.0] to @racket[1.0] is given to @racket[flasin] or @racket[flacos], or when a negative number is given to @racket[fllog] or @racket[flsqrt].} @defproc[(flexpt [a flonum?] [b flonum?]) flonum?]{ Like @racket[expt], but constrained to consume and produce @tech{flonums}. Due to the result constraint, the results compared to @racket[expt] differ in the following cases: @margin-note*{These special cases correspond to @tt{pow} in C99 @cite["C99"].} @; @itemlist[#:style 'compact @item{@racket[(flexpt -1.0 +inf.0)] --- @racket[1.0]} @item{@racket[(flexpt a +inf.0)] where @racket[a] is negative --- @racket[(expt (abs a) +inf.0)]} @item{@racket[(flexpt a -inf.0)] where @racket[a] is negative --- @racket[(expt (abs a) -inf.0)]} @item{@racket[(expt -inf.0 b)] where @racket[b] is a non-integer: @itemlist[#:style 'compact @item{@racket[b] is negative --- @racket[+0.0]} @item{@racket[b] is positive --- @racket[+inf.0]}]} @item{@racket[(flexpt a b)] where @racket[a] is negative and @racket[b] is not an integer --- @racket[+nan.0]} ]} @defproc[(->fl [a exact-integer?]) flonum?]{ Like @racket[exact->inexact], but constrained to consume exact integers, so the result is always a @tech{flonum}.} @defproc[(fl->exact-integer [a flonum?]) exact-integer?]{ Like @racket[inexact->exact], but constrained to consume an @tech{integer} @tech{flonum}, so the result is always an exact integer.} @deftogether[( @defproc[(make-flrectangular [a flonum?] [b flonum?]) (and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))] @defproc[(flreal-part [a (and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))]) flonum?] @defproc[(flimag-part [a (and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))]) flonum?] )]{ Like @racket[make-rectangular], @racket[real-part], and @racket[imag-part], but both parts of the complex number must be inexact.} @defproc[(flrandom [rand-gen pseudo-random-generator?]) (and flonum? (>/c 0) (