#### 5.1.2 Functions and Variables for Numbers

Function: bfloat (expr)

  Converts all numbers and functions of numbers in expr to bigfloat numbers. The number of significant digits in the resulting bigfloats is specified by the global variable `fpprec`.

  When `float2bf` is `false` a warning message is printed when a floating point number is converted into a bigfloat number (since this may lead to loss of precision).

  ·

  Categories: Numerical evaluation

Function: bfloatp (expr)

  Returns `true` if expr is a bigfloat number, otherwise `false`.

  ·

  Categories: Numerical evaluation ·Predicate functions

Option variable: bftorat

  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.e-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

  ·

  Categories: Numerical evaluation

Option variable: bftrunc

  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`.

  ·

  Categories: Numerical evaluation

Function: evenp (expr)

  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`.

  ·

  Categories: Predicate functions

Function: float (expr)

  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.

  ·

  Categories: Numerical evaluation ·Evaluation flags

Option variable: float2bf

  Default value: `true`

  When `float2bf` is `false`, a warning message is printed when a floating point number is converted into a bigfloat number (since this may lead to loss of precision).

  ·

  Categories: Numerical evaluation

Function: floatnump (expr)

  Returns `true` if expr is a floating point number, otherwise `false`.

  ·

  Categories: Numerical evaluation ·Predicate functions

Option variable: fpprec

  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`.

  ·

  Categories: Numerical evaluation

Option variable: 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.

  ·

  Categories: Numerical evaluation ·Display flags and variables

Function: integerp (expr)

  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

  ·

  Categories: Predicate functions

Option variable: m1pbranch

  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

  ·

  Categories: Expressions ·Global flags

Function: nonnegintegerp (n)

  Return `true` if and only if `n >= 0` and n is an integer.

  ·

  Categories: Package linearalgebra ·Predicate functions

Function: numberp (expr)

  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]

  ·

  Categories: Predicate functions

Option variable: numer

  `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]

  ·

  Categories: Numerical evaluation ·Evaluation flags

Option variable: numer_pbranch

  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

  ·

  Categories: Numerical evaluation

Function: numerval (x_1, expr_1, …, var_n, expr_n)

  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.

  ·

  Categories: Declarations and inferences ·Numerical evaluation

Function: oddp (expr)

  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`.

  ·

  Categories: Predicate functions

Option variable: ratepsilon

  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.

  ·

  Categories: Numerical evaluation ·Rational expressions

Function: rationalize (expr)

  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

  ·

  Categories: Numerical evaluation

Function: ratnump (expr)

  Returns `true` if expr is a literal integer or ratio of literal integers, otherwise `false`.

  ·

  Categories: Predicate functions ·Rational expressions