1 Constants and Elementary Functions
For convenience, math/base re-exports racket/math
as well as providing the values document below.
In general, the functions provided by math/base are elementary
functions, or those functions that can be defined in terms of a finite number of
arithmetic operations, logarithms, exponentials, trigonometric functions, and constants.
For others, see math/special-functions and math/distributions.
If you need more accurate approximations than the following flonums, see, for example,
phi.bf and bigfloat->rational.
|> (exp 1)|
Returns a new complex number with a flonum real part and a flonum imaginary part.
Analogous to real->double-flonum
Returns #t when x is an integer power of 2.
Like (apply + xs)
, but incurs rounding error only once when adding inexact numbers.
(In fact, the inexact numbers in xs
are summed separately using flsum
1.3 Random Number Generation
Returns a random natural number less than k
, which must be positive.
Use (random-natural k)
instead of (random k)
could be larger than 4294967087
Returns a random integer n
such that (<= a n)
and (< n b)
Returns a random natural smaller than (expt 2 num)
must be positive.
For powers of two, this is faster than using random-natural
is implemented in terms of random-bits
, using biased rejection sampling.
As an example of use, the significands of the numbers returned by bfrandom
are chosen by (random-bits (bf-precision)).
1.4 Measuring Error
Usually computes (abs (- x r))
using exact rationals, but handles non-rational
reals such as +inf.0
Measures how close an approximation x is to the correct value r,
relative to the magnitude of r.
This function usually computes (abs (/ (- x r) r)) using exact rationals,
but handles non-rational reals such as +inf.0 specially, as well as
r = 0.
In the last two examples, relative error is high because the result is near zero. (Compare
the same examples with absolute-error
.) Because flonums are particularly dense
near zero, this makes relative error better than absolute error for measuring the error
in a flonum approximation. An even better one is error in ulps
; see flulp-error