6.1
1 Constants and Elementary Functions
Link to this section with
@secref["base" #:doc '(lib "math/scribblings/math.scrbl")]
Link to this section with
@secref["base" #:doc '(lib "math/scribblings/math.scrbl")]
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.
1.1 Constants
Link to this section with
@secref["Constants" #:doc '(lib "math/scribblings/math.scrbl")]
Link to this section with
@secref["Constants" #:doc '(lib "math/scribblings/math.scrbl")]
If you need more accurate approximations than the following flonums, see, for example,
phi.bf and bigfloat->rational.
> euler.0 |
2.718281828459045 |
> (exp 1) |
2.718281828459045 |
1.2 Functions
Link to this section with
@secref["Functions" #:doc '(lib "math/scribblings/math.scrbl")]
Link to this section with
@secref["Functions" #:doc '(lib "math/scribblings/math.scrbl")]
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
Link to this section with
@secref["Random_Number_Generation"
#:doc '(lib "math/scribblings/math.scrbl")]
Link to this section with
@secref["Random_Number_Generation"
#:doc '(lib "math/scribblings/math.scrbl")]
Returns a random natural number less than
k, which must be positive.
Use
(random-natural k) instead of
(random k) when
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);
num must be positive.
For powers of two, this is faster than using
random-natural, which
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
Link to this section with
@secref["Measuring_Error" #:doc '(lib "math/scribblings/math.scrbl")]
Link to this section with
@secref["Measuring_Error" #:doc '(lib "math/scribblings/math.scrbl")]
Usually computes
(abs (- x r)) using exact rationals, but handles non-rational
reals such as
+inf.0 specially.
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.