# Number Class Reference

A number. More...

`#include <Number.h>`

List of all members.

## Public Member Functions
| Number ()
| Number (string number, const ParseOptions &po=default_parse_options)
| Number (int numerator, int denominator=1, int exp_10=0)
| Number (const Number &o)
void | set (string number, const ParseOptions &po=default_parse_options)
void | set (int numerator, int denominator=1, int exp_10=0)
void | setInfinity ()
void | setPlusInfinity ()
void | setMinusInfinity ()
void | setFloat (double d_value)
void | setInternal (const cln::cl_N &cln_value)
void | setImaginaryPart (const Number &o)
void | setImaginaryPart (int numerator, int denominator=1, int exp_10=0)
void | set (const Number &o)
void | clear ()
const cln::cl_N & | internalNumber () const
double | floatValue () const
int | intValue (bool *overflow=NULL) const
bool | isApproximate () const
bool | isApproximateType () const
void | setApproximate (bool is_approximate=true)
int | precision () const
void | setPrecision (int prec)
bool | isUndefined () const
bool | isInfinite () const
bool | isInfinity () const
bool | isPlusInfinity () const
bool | isMinusInfinity () const
Number | realPart () const
Number | imaginaryPart () const
Number | numerator () const
Number | denominator () const
Number | complexNumerator () const
Number | complexDenominator () const
void | operator= (const Number &o)
void | operator-- (int)
void | operator++ (int)
Number | operator- () const
Number | operator* (const Number &o) const
Number | operator/ (const Number &o) const
Number | operator+ (const Number &o) const
Number | operator- (const Number &o) const
Number | operator^ (const Number &o) const
Number | operator && (const Number &o) const
Number | operator|| (const Number &o) const
Number | operator! () const
void | operator*= (const Number &o)
void | operator/= (const Number &o)
void | operator+= (const Number &o)
void | operator-= (const Number &o)
void | operator^= (const Number &o)
bool | operator== (const Number &o) const
bool | operator!= (const Number &o) const
bool | bitAnd (const Number &o)
bool | bitOr (const Number &o)
bool | bitXor (const Number &o)
bool | bitNot ()
bool | bitEqv (const Number &o)
bool | shiftLeft (const Number &o)
bool | shiftRight (const Number &o)
bool | shift (const Number &o)
bool | hasRealPart () const
bool | hasImaginaryPart () const
bool | isComplex () const
bool | isInteger () const
Number | integer () const
bool | isRational () const
bool | isReal () const
bool | isFraction () const
bool | isZero () const
bool | isOne () const
bool | isTwo () const
bool | isI () const
bool | isMinusI () const
bool | isMinusOne () const
bool | isNegative () const
bool | isNonNegative () const
bool | isPositive () const
bool | isNonPositive () const
bool | realPartIsNegative () const
bool | realPartIsPositive () const
bool | imaginaryPartIsNegative () const
bool | imaginaryPartIsPositive () const
bool | hasNegativeSign () const
bool | hasPositiveSign () const
bool | equalsZero () const
bool | equals (const Number &o) const
bool | equalsApproximately (const Number &o, int prec) const
ComparisonResult | compare (const Number &o) const
ComparisonResult | compareApproximately (const Number &o, int prec=EQUALS_PRECISION_LOWEST) const
ComparisonResult | compareImaginaryParts (const Number &o) const
ComparisonResult | compareRealParts (const Number &o) const
bool | isGreaterThan (const Number &o) const
bool | isLessThan (const Number &o) const
bool | isGreaterThanOrEqualTo (const Number &o) const
bool | isLessThanOrEqualTo (const Number &o) const
bool | isEven () const
bool | denominatorIsEven () const
bool | denominatorIsTwo () const
bool | numeratorIsEven () const
bool | numeratorIsOne () const
bool | numeratorIsMinusOne () const
bool | isOdd () const
int | integerLength () const
bool | add (const Number &o)
bool | subtract (const Number &o)
bool | multiply (const Number &o)
bool | divide (const Number &o)
bool | recip ()
bool | raise (const Number &o, bool try_exact=true)
bool | exp10 (const Number &o)
bool | exp2 (const Number &o)
bool | exp10 ()
bool | exp2 ()
bool | square ()
bool | negate ()
void | setNegative (bool is_negative)
bool | abs ()
bool | signum ()
bool | round (const Number &o)
bool | floor (const Number &o)
bool | ceil (const Number &o)
bool | trunc (const Number &o)
bool | mod (const Number &o)
bool | isqrt ()
bool | round ()
bool | floor ()
bool | ceil ()
bool | trunc ()
bool | frac ()
bool | rem (const Number &o)
bool | smod (const Number &o)
bool | irem (const Number &o)
bool | irem (const Number &o, Number &q)
bool | iquo (const Number &o)
bool | iquo (const Number &o, Number &r)
int | getBoolean () const
void | toBoolean ()
void | setTrue (bool is_true=true)
void | setFalse ()
void | setLogicalNot ()
void | e ()
void | pi ()
void | catalan ()
void | euler ()
bool | zeta ()
bool | sin ()
bool | asin ()
bool | sinh ()
bool | asinh ()
bool | cos ()
bool | acos ()
bool | cosh ()
bool | acosh ()
bool | tan ()
bool | atan ()
bool | tanh ()
bool | atanh ()
bool | ln ()
bool | log (const Number &o)
bool | exp ()
bool | lambertW ()
bool | gcd (const Number &o)
bool | lcm (const Number &o)
bool | factorial ()
bool | multiFactorial (const Number &o)
bool | doubleFactorial ()
bool | binomial (const Number &m, const Number &k)
bool | factorize (vector< Number > &factors)
bool | add (const Number &o, MathOperation op)
string | printNumerator (int base=10, bool display_sign=true, BaseDisplay base_display=BASE_DISPLAY_NORMAL, bool lower_case=false) const
string | printDenominator (int base=10, bool display_sign=true, BaseDisplay base_display=BASE_DISPLAY_NORMAL, bool lower_case=false) const
string | printImaginaryNumerator (int base=10, bool display_sign=true, BaseDisplay base_display=BASE_DISPLAY_NORMAL, bool lower_case=false) const
string | printImaginaryDenominator (int base=10, bool display_sign=true, BaseDisplay base_display=BASE_DISPLAY_NORMAL, bool lower_case=false) const
string | print (const PrintOptions &po=default_print_options, const InternalPrintStruct &ips=top_ips) const
## Protected Member Functions
void | removeFloatZeroPart ()
void | testApproximate ()
void | testInteger ()
void | setPrecisionAndApproximateFrom (const Number &o)
## Protected Attributes
cln::cl_N | value
bool | b_inf
bool | b_pinf
bool | b_minf
bool | b_approx
int | i_precision

## Detailed Description

A number.

Can be rational, floating point, complex or infinite. Has arbitrary precision (uses Calculator::precision()) and infinitely large rational numbers. Implimented using CLN numbers.

## Constructor & Destructor Documentation

Number::Number | ( |  | ) |

Constructs a number initialized as zero.

Number::Number | ( | string | number,
|  | const ParseOptions & | po = `default_parse_options` |
| ) |  |  |

Constructs a number parsing a text string.

Parameters:

  | number | Text string to read number from.
  | po | Options for parsing the text string.

Number::Number | ( | int | numerator,
|  | int | denominator = `1`,
|  | int | exp_10 = `0` |
| ) |  |  |

Constructs a rational number.

Parameters:

  | numerator |
  | denominator |
  | exp_10 |

Number::Number | ( | const Number & | o | ) |

Constructs a copy of a number.

## Member Function Documentation

int Number::intValue | ( | bool * | overflow = `NULL` | ) | const

Converts a number to an integer. If the number does not represent an integer it will rounded using round().

Parameters:

  `[out]` | overflow | If overflow is non-null it will be set to true if the number was to large to fit in an int.

Returns:
  Resulting integer.

bool Number::isApproximate | ( |  | ) | const

Returns true if the number is approximate.

Returns:
  true if the number is approximate.

bool Number::isApproximateType | ( |  | ) | const

Returns true if the number has an approximate representation/is of approximate type -- if it is a floating point number. Numbers of approximate type are always approximate, but the reversed relation is not always true.

Returns:
  true if the number has an approximate representation.

void Number::setApproximate | ( | bool | is_approximate = `true` | ) |

Defines the number as approximate or exact. If a number of approximate type is set as exact, it will be converted to a rational number.

Parameters:

  | is_approximate | If the number shall be regarded as approximate.

int Number::precision | ( |  | ) | const

Returns the.precision of the number.

Returns:
  Precision of the number or -1 if the number is exact or the precision has not been set.

bool Number::isInfinite | ( |  | ) | const

Returns true if the number is infinity, plus infinity or minus infinity.

Returns:
  true if the number is infinite.

bool Number::isInfinity | ( |  | ) | const

Returns true if the number is infinity, if the number is plus or minus infinity (which is not known).

Returns:
  true if the number is infinity.

bool Number::isPlusInfinity | ( |  | ) | const

Returns true if the number is plus infinity.

Returns:
  true if the number is plus infinity.

bool Number::isMinusInfinity | ( |  | ) | const

Returns true if the number is minus infinity.

Returns:
  true if the number is minus infinity.

Number Number::realPart | ( |  | ) | const

Returns the real part of the number if it is complex, or a copy if it is real.

Returns:
  true if the real part of a complex number.

Number Number::imaginaryPart | ( |  | ) | const

Returns the imaginary part as real number of the number if it is complex, or zero if it is real.

Returns:
  true if the imaginary part of a complex number.

bool Number::add | ( | const Number & | o | ) |

Add to the number (x+o).

Parameters:

  | o | Number to add.

Returns:
  true if the operation was successful.

bool Number::subtract | ( | const Number & | o | ) |

Subtracts from to the number (x-o).

Parameters:

  | o | Number to subtract.

Returns:
  true if the operation was successful.

bool Number::multiply | ( | const Number & | o | ) |

Multiply the number (x*o).

Parameters:

  | o | Number to multiply with.

Returns:
  true if the operation was successful.

bool Number::divide | ( | const Number & | o | ) |

Divide the number (x/o).

Parameters:

  | o | Number to divide by.

Returns:
  true if the operation was successful.

bool Number::recip | ( |  | ) |

Invert the number (1/x).

Returns:
  true if the operation was successful.

bool Number::raise | ( | const Number & | o,
|  | bool | try_exact = `true` |
| ) |  |  |

Raise the number (x^o).

Parameters:

  | o | Number to raise to.
  | try_exact | If an exact solution should be tried first (might be slow).

Returns:
  true if the operation was successful.

bool Number::exp10 | ( | const Number & | o | ) |

Multiply the number with a power of ten (x*10^o).

Parameters:

  | o | Number to raise 10 by.

Returns:
  true if the operation was successful.

bool Number::exp2 | ( | const Number & | o | ) |

Multiply the number with a power of two (x*2^o).

Parameters:

  | o | Number to raise 2 by.

Returns:
  true if the operation was successful.

bool Number::exp10 | ( |  | ) |

Set the number to ten raised by the number (10^x).

Returns:
  true if the operation was successful.

bool Number::exp2 | ( |  | ) |

Set the number to two raised by the number (2^x).

Returns:
  true if the operation was successful.

bool Number::square | ( |  | ) |

Raise the number by two (x^2).

Returns:
  true if the operation was successful.

bool Number::negate | ( |  | ) |

Negate the number (-x).

Returns:
  true if the operation was successful.

void Number::e | ( |  | ) |

Set the number to e, the base of natural logarithm, calculated with the current default precision.

void Number::pi | ( |  | ) |

Set the number to pi, Archimede's constant, calculated with the current default precision.

void Number::catalan | ( |  | ) |

Set the number to Catalan's constant, calculated with the current default precision.

void Number::euler | ( |  | ) |

Set the number to Euler's constant, calculated with the current default precision.

bool Number::zeta | ( |  | ) |

Set the number to Riemann's zeta with the number as integral point. The number must be an integer greater than one.

Returns:
  true if the calculation was successful.

The documentation for this class was generated from the following file:

- libqalculate/Number.h