Previous: Introduction to Numbers, Up: Numbers [Contents][Index]
bfloat
replaces integers, rationals, floating point numbers, and some symbolic constants
in expr with bigfloat (variable-precision floating point) numbers.
The constants %e
, %gamma
, %phi
, and %pi
are replaced by a numerical approximation.
However, %e
in %e^x
is not replaced by a numeric value
unless bfloat(x)
is a number.
bfloat
also causes numerical evaluation of some built-in functions,
namely trigonometric functions, exponential functions, abs
, and log
.
The number of significant digits in the resulting bigfloats is specified by the
global variable fpprec
.
Bigfloats already present in expr are replaced with values which have
precision specified by the current value of fpprec
.
When float2bf
is false
, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.
Examples:
bfloat
replaces integers, rationals, floating point numbers, and some symbolic constants
in expr with bigfloat numbers.
(%i1) bfloat([123, 17/29, 1.75]); (%o1) [1.23b2, 5.862068965517241b-1, 1.75b0] (%i2) bfloat([%e, %gamma, %phi, %pi]); (%o2) [2.718281828459045b0, 5.772156649015329b-1, 1.618033988749895b0, 3.141592653589793b0] (%i3) bfloat((f(123) + g(h(17/29)))/(x + %gamma)); 1.0b0 (g(h(5.862068965517241b-1)) + f(1.23b2)) (%o3) ---------------------------------------------- x + 5.772156649015329b-1
bfloat
also causes numerical evaluation of some built-in functions.
(%i1) bfloat(sin(17/29)); (%o1) 5.532051841609784b-1 (%i2) bfloat(exp(%pi)); (%o2) 2.314069263277927b1 (%i3) bfloat(abs(-%gamma)); (%o3) 5.772156649015329b-1 (%i4) bfloat(log(%phi)); (%o4) 4.812118250596035b-1
Returns true
if expr is a bigfloat number, otherwise false
.
Default value: false
bftorat
controls the conversion of bfloats to rational numbers. When
bftorat
is false
, ratepsilon
will be used to control the
conversion (this results in relatively small rational numbers). When
bftorat
is true
, the rational number generated will accurately
represent the bfloat.
Note: bftorat
has no effect on the transformation to rational numbers
with the function rationalize
.
Example:
(%i1) ratepsilon:1e-4; (%o1) 1.0e-4 (%i2) rat(bfloat(11111/111111)), bftorat:false; `rat' replaced 9.99990999991B-2 by 1/10 = 1.0B-1 1 (%o2)/R/ -- 10 (%i3) rat(bfloat(11111/111111)), bftorat:true; `rat' replaced 9.99990999991B-2 by 11111/111111 = 9.99990999991B-2 11111 (%o3)/R/ ------ 111111
Default value: true
bftrunc
causes trailing zeroes in non-zero bigfloat numbers not to be
displayed. Thus, if bftrunc
is false
, bfloat (1)
displays as 1.000000000000000B0
. Otherwise, this is displayed as
1.0B0
.
Returns true
if expr is a literal even integer, otherwise
false
.
evenp
returns false
if expr is a symbol, even if expr
is declared even
.
Converts integers, rational numbers and bigfloats in expr to floating
point numbers. It is also an evflag
, float
causes
non-integral rational numbers and bigfloat numbers to be converted to floating
point.
Default value: true
When float2bf
is false
, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.
Returns true
if expr is a floating point number, otherwise
false
.
Default value: 16
fpprec
is the number of significant digits for arithmetic on bigfloat
numbers. fpprec
does not affect computations on ordinary floating point
numbers.
See also bfloat
and fpprintprec
.
Default value: 0
fpprintprec
is the number of digits to print when printing an ordinary
float or bigfloat number.
For ordinary floating point numbers,
when fpprintprec
has a value between 2 and 16 (inclusive),
the number of digits printed is equal to fpprintprec
.
Otherwise, fpprintprec
is 0, or greater than 16,
and the number of digits printed is 16.
For bigfloat numbers,
when fpprintprec
has a value between 2 and fpprec
(inclusive),
the number of digits printed is equal to fpprintprec
.
Otherwise, fpprintprec
is 0, or greater than fpprec
,
and the number of digits printed is equal to fpprec
.
For both ordinary floats and bigfloats,
trailing zero digits are suppressed.
The actual number of digits printed is less than fpprintprec
if there are trailing zero digits.
fpprintprec
cannot be 1.
Returns true
if expr is a literal numeric integer, otherwise
false
.
integerp
returns false
if expr is a symbol, even if expr
is declared integer
.
Examples:
(%i1) integerp (0); (%o1) true (%i2) integerp (1); (%o2) true (%i3) integerp (-17); (%o3) true (%i4) integerp (0.0); (%o4) false (%i5) integerp (1.0); (%o5) false (%i6) integerp (%pi); (%o6) false (%i7) integerp (n); (%o7) false (%i8) declare (n, integer); (%o8) done (%i9) integerp (n); (%o9) false
Default value: false
m1pbranch
is the principal branch for -1
to a power.
Quantities such as (-1)^(1/3)
(that is, an "odd" rational exponent) and
(-1)^(1/4)
(that is, an "even" rational exponent) are handled as follows:
domain:real (-1)^(1/3): -1 (-1)^(1/4): (-1)^(1/4) domain:complex m1pbranch:false m1pbranch:true (-1)^(1/3) 1/2+%i*sqrt(3)/2 (-1)^(1/4) sqrt(2)/2+%i*sqrt(2)/2
Return true
if and only if n >= 0
and n is an integer.
Returns true
if expr is a literal integer, rational number,
floating point number, or bigfloat, otherwise false
.
numberp
returns false
if expr is a symbol, even if expr
is a symbolic number such as %pi
or %i
, or declared to be
even
, odd
, integer
, rational
, irrational
,
real
, imaginary
, or complex
.
Examples:
(%i1) numberp (42); (%o1) true (%i2) numberp (-13/19); (%o2) true (%i3) numberp (3.14159); (%o3) true (%i4) numberp (-1729b-4); (%o4) true (%i5) map (numberp, [%e, %pi, %i, %phi, inf, minf]); (%o5) [false, false, false, false, false, false] (%i6) declare (a, even, b, odd, c, integer, d, rational, e, irrational, f, real, g, imaginary, h, complex); (%o6) done (%i7) map (numberp, [a, b, c, d, e, f, g, h]); (%o7) [false, false, false, false, false, false, false, false]
numer
causes some mathematical functions (including exponentiation)
with numerical arguments to be evaluated in floating point. It causes
variables in expr
which have been given numerals to be replaced by
their values. It also sets the float
switch on.
See also %enumer
.
Examples:
(%i1) [sqrt(2), sin(1), 1/(1+sqrt(3))]; 1 (%o1) [sqrt(2), sin(1), -----------] sqrt(3) + 1
(%i2) [sqrt(2), sin(1), 1/(1+sqrt(3))],numer; (%o2) [1.414213562373095, 0.8414709848078965, 0.3660254037844387]
Default value: false
The option variable numer_pbranch
controls the numerical evaluation of
the power of a negative integer, rational, or floating point number. When
numer_pbranch
is true
and the exponent is a floating point number
or the option variable numer
is true
too, Maxima evaluates
the numerical result using the principal branch. Otherwise a simplified, but
not an evaluated result is returned.
Examples:
(%i1) (-2)^0.75; 0.75 (%o1) (- 2)
(%i2) (-2)^0.75,numer_pbranch:true; (%o2) 1.189207115002721 %i - 1.189207115002721
(%i3) (-2)^(3/4); 3/4 3/4 (%o3) (- 1) 2
(%i4) (-2)^(3/4),numer; 0.75 (%o4) 1.681792830507429 (- 1)
(%i5) (-2)^(3/4),numer,numer_pbranch:true; (%o5) 1.189207115002721 %i - 1.189207115002721
Declares the variables x_1
, …, x_n to have
numeric values equal to expr_1
, …, expr_n
.
The numeric value is evaluated and substituted for the variable
in any expressions in which the variable occurs if the numer
flag is
true
. See also ev
.
The expressions expr_1
, …, expr_n
can be any expressions,
not necessarily numeric.
Returns true
if expr is a literal odd integer, otherwise
false
.
oddp
returns false
if expr is a symbol, even if expr
is declared odd
.
Default value: 2.0e-15
ratepsilon
is the tolerance used in the conversion
of floating point numbers to rational numbers, when the option variable
bftorat
has the value false
. See bftorat
for an example.
Convert all double floats and big floats in the Maxima expression expr to
their exact rational equivalents. If you are not familiar with the binary
representation of floating point numbers, you might be surprised that
rationalize (0.1)
does not equal 1/10. This behavior isn’t special to
Maxima – the number 1/10 has a repeating, not a terminating, binary
representation.
(%i1) rationalize (0.5); 1 (%o1) - 2
(%i2) rationalize (0.1); 3602879701896397 (%o2) ----------------- 36028797018963968
(%i3) fpprec : 5$
(%i4) rationalize (0.1b0); 209715 (%o4) ------- 2097152
(%i5) fpprec : 20$
(%i6) rationalize (0.1b0); 236118324143482260685 (%o6) ---------------------- 2361183241434822606848
(%i7) rationalize (sin (0.1*x + 5.6)); 3602879701896397 x 3152519739159347 (%o7) sin(------------------ + ----------------) 36028797018963968 562949953421312
Returns true
if expr is a literal integer or ratio of literal
integers, otherwise false
.
Previous: Introduction to Numbers, Up: Numbers [Contents][Index]