1 Constants and Elementary Functions
(require math/base) | package: math-lib |
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
If you need more accurate approximations than the following flonums, see, for example, phi.bf and bigfloat->rational.
value
> phi.0 1.618033988749895
value
value
> gamma.0 0.5772156649015329
value
> catalan.0 0.915965594177219
1.2 Functions
procedure
(float-complex? v) → Boolean
v : Any
procedure
x : Number
procedure
(power-of-two? x) → Boolean
x : Real
> (power-of-two? 1.0) #t
> (power-of-two? 1/2) #t
> (power-of-two? (flnext 2.0)) #f
1.3 Random Number Generation
procedure
(random-natural k) → Natural
k : Integer
procedure
(random-integer a b) → Integer
a : Integer b : Integer
procedure
(random-bits num) → Natural
num : Integer
As an example of use, the significands of the numbers returned by bfrandom are chosen by (random-bits (bf-precision)).
1.4 Measuring Error
procedure
(absolute-error x r) → Real
x : Real r : Real
> (absolute-error 1/2 1/2) 0
> (absolute-error 0.14285714285714285 1/7) 7.93016446160826e-18
> (absolute-error +inf.0 +inf.0) 0.0
> (absolute-error +inf.0 +nan.0) +inf.0
> (absolute-error 1e-20 0.0) 1e-20
> (absolute-error (- 1.0 (fl 4999999/5000000)) 1/5000000) 5.751132903242251e-18
procedure
(relative-error x r) → Real
x : Real r : Real
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.
> (relative-error 1/2 1/2) 0
> (relative-error 0.14285714285714285 1/7) 5.551115123125783e-17
> (relative-error +inf.0 +inf.0) 0.0
> (relative-error +inf.0 +nan.0) +inf.0
> (relative-error 1e-20 0.0) +inf.0
> (relative-error (- 1.0 (fl 4999999/5000000)) 1/5000000) 2.8755664516211255e-11