• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kcalc/knumber
 

kcalc/knumber

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
KNumber Class Reference

#include <knumber.h>

Public Types

enum  NumType { SpecialType , IntegerType , FractionType , FloatType }
 
enum  ErrorType { UndefinedNumber , Infinity , MinusInfinity }
 

Public Member Functions

 KNumber (signed int num=0)
 
 KNumber (unsigned int num)
 
 KNumber (signed long int num)
 
 KNumber (unsigned long int num)
 
 KNumber (unsigned long long int num)
 
 KNumber (double num)
 
 KNumber (KNumber const &num)
 
 KNumber (TQString const &num)
 
KNumber const & operator= (KNumber const &num)
 
NumType type (void) const
 
TQString const toTQString (int width=-1, int prec=-1) const
 
KNumber const abs (void) const
 
KNumber const sqrt (void) const
 
KNumber const cbrt (void) const
 
KNumber const integerPart (void) const
 
KNumber const power (KNumber const &exp) const
 
KNumber const operator+ (KNumber const &arg2) const
 
KNumber const operator- (void) const
 
KNumber const operator- (KNumber const &arg2) const
 
KNumber const operator* (KNumber const &arg2) const
 
KNumber const operator/ (KNumber const &arg2) const
 
KNumber const operator% (KNumber const &arg2) const
 
KNumber const operator& (KNumber const &arg2) const
 
KNumber const operator| (KNumber const &arg2) const
 
KNumber const operator<< (KNumber const &arg2) const
 
KNumber const operator>> (KNumber const &arg2) const
 
 operator bool (void) const
 
 operator signed long int (void) const
 
 operator unsigned long int (void) const
 
 operator unsigned long long int (void) const
 
 operator double (void) const
 
bool const operator== (KNumber const &arg2) const
 
bool const operator!= (KNumber const &arg2) const
 
bool const operator> (KNumber const &arg2) const
 
bool const operator< (KNumber const &arg2) const
 
bool const operator>= (KNumber const &arg2) const
 
bool const operator<= (KNumber const &arg2) const
 
KNumber & operator+= (KNumber const &arg)
 
KNumber & operator-= (KNumber const &arg)
 

Static Public Member Functions

static void setDefaultFloatOutput (bool flag)
 
static void setDefaultFractionalInput (bool flag)
 
static void setDefaultFloatPrecision (unsigned int prec)
 
static void setSplitoffIntegerForFractionOutput (bool flag)
 

Static Public Attributes

static KNumber const Zero
 
static KNumber const One
 
static KNumber const MinusOne
 
static KNumber const Pi
 
static KNumber const Euler
 
static KNumber const NotDefined
 

Detailed Description

Class that provides arbitrary precision numbers.

KNumber provides access to arbitrary precision numbers from within KDE.

KNumber is based on the GMP (GNU Multiprecision) library and provides transparent support to integer, fractional and floating point number. It contains rudimentary error handling, and also includes methods for converting the numbers to TQStrings for output, and to read TQStrings to obtain a KNumber.

The different types of numbers that can be represented by objects of this class will be described below:

  • NumType::SpecialType - This type represents an error that has occurred, e.g. trying to divide 1 by 0 gives an object that represents infinity.
  • NumType::IntegerType - The number is an integer. It can be arbitrarily large (restricted by the memory of the system).
  • NumType::FractionType - A fraction is a number of the form denominator divided by nominator, where both denominator and nominator are integers of arbitrary size.
  • NumType::FloatType - The number is of floating point type. These numbers are usually rounded, so that they do not represent precise values.
Author
Klaus Niederkrueger knied.nosp@m.erk@.nosp@m.math..nosp@m.uni-.nosp@m.koeln.nosp@m..de

Definition at line 62 of file knumber.h.

Member Enumeration Documentation

◆ ErrorType

enum KNumber::ErrorType

A KNumber that represents an error, i.e.

that is of type NumType::SpecialType can further distinguished:

  • ErrorType::UndefinedNumber - This is e.g. the result of taking the square root of a negative number or computing $ \infty - \infty $.
  • ErrorType::Infinity - Such a number can be e.g. obtained by dividing 1 by 0. Some further calculations are still allowed, e.g. $ \infty + 5 $ still gives $\infty$.
  • ErrorType::MinusInfinity - MinusInfinity behaves similarly to infinity above. It can be obtained by changing the sign of infinity.

Definition at line 105 of file knumber.h.

◆ NumType

enum KNumber::NumType

KNumber tries to provide transparent access to the following type of numbers:

  • NumType::SpecialType - Some type of error has occurred, further inspection with KNumber::ErrorType
  • NumType::IntegerType - the number is an integer
  • NumType::FractionType - the number is a fraction
  • NumType::FloatType - the number is of floating point type

Definition at line 86 of file knumber.h.

Constructor & Destructor Documentation

◆ KNumber() [1/8]

KNumber::KNumber ( signed int  num = 0)

Definition at line 44 of file knumber.cpp.

◆ KNumber() [2/8]

KNumber::KNumber ( unsigned int  num)

Definition at line 49 of file knumber.cpp.

◆ KNumber() [3/8]

KNumber::KNumber ( signed long int  num)

Definition at line 54 of file knumber.cpp.

◆ KNumber() [4/8]

KNumber::KNumber ( unsigned long int  num)

Definition at line 59 of file knumber.cpp.

◆ KNumber() [5/8]

KNumber::KNumber ( unsigned long long int  num)

Definition at line 64 of file knumber.cpp.

◆ KNumber() [6/8]

KNumber::KNumber ( double  num)

Definition at line 69 of file knumber.cpp.

◆ KNumber() [7/8]

KNumber::KNumber ( KNumber const &  num)

Definition at line 77 of file knumber.cpp.

◆ KNumber() [8/8]

KNumber::KNumber ( TQString const &  num)

Definition at line 96 of file knumber.cpp.

◆ ~KNumber()

KNumber::~KNumber ( )
inline

Definition at line 119 of file knumber.h.

Member Function Documentation

◆ abs()

KNumber const KNumber::abs ( void  ) const

Compute the absolute value, i.e.

x.abs() returns the value

\[ \left\{\begin{array}{cl} x, & x \ge 0 \\ -x, & x <
 0\end{array}\right.\]

This method works for $ x = \infty $ and $ x = -\infty $.

Definition at line 437 of file knumber.cpp.

◆ cbrt()

KNumber const KNumber::cbrt ( void  ) const

Compute the cube root.

If x is an integer or a fraction, then x.cbrt() tries to compute the exact cube root. If the cube root is not a fraction, then a float is returned, but

WARNING: A float cube root is computed as a standard double that is later transformed back into a KNumber.

This method works for $ x = \infty $ giving $ \infty $, and for $ x = -\infty $ giving $ -\infty $.

Definition at line 447 of file knumber.cpp.

◆ integerPart()

KNumber const KNumber::integerPart ( void  ) const

Truncates a KNumber to its integer type returning a number of type NumType::IntegerType.

If $ x = \pm\infty $, integerPart leaves the value unchanged, i.e. it returns $ \pm\infty $.

Definition at line 467 of file knumber.cpp.

◆ operator bool()

KNumber::operator bool ( void  ) const

Definition at line 647 of file knumber.cpp.

◆ operator double()

KNumber::operator double ( void  ) const

Definition at line 684 of file knumber.cpp.

◆ operator signed long int()

KNumber::operator signed long int ( void  ) const

Definition at line 654 of file knumber.cpp.

◆ operator unsigned long int()

KNumber::operator unsigned long int ( void  ) const

Definition at line 659 of file knumber.cpp.

◆ operator unsigned long long int()

KNumber::operator unsigned long long int ( void  ) const

Definition at line 664 of file knumber.cpp.

◆ operator!=()

bool const KNumber::operator!= ( KNumber const &  arg2) const
inline

Definition at line 252 of file knumber.h.

◆ operator%()

KNumber const KNumber::operator% ( KNumber const &  arg2) const

Definition at line 563 of file knumber.cpp.

◆ operator&()

KNumber const KNumber::operator& ( KNumber const &  arg2) const

Definition at line 579 of file knumber.cpp.

◆ operator*()

KNumber const KNumber::operator* ( KNumber const &  arg2) const

Definition at line 538 of file knumber.cpp.

◆ operator+()

KNumber const KNumber::operator+ ( KNumber const &  arg2) const

Definition at line 521 of file knumber.cpp.

◆ operator+=()

KNumber & KNumber::operator+= ( KNumber const &  arg)

Definition at line 177 of file knumber.cpp.

◆ operator-() [1/2]

KNumber const KNumber::operator- ( KNumber const &  arg2) const

Definition at line 533 of file knumber.cpp.

◆ operator-() [2/2]

KNumber const KNumber::operator- ( void  ) const

Definition at line 511 of file knumber.cpp.

◆ operator-=()

KNumber & KNumber::operator-= ( KNumber const &  arg)

Definition at line 203 of file knumber.cpp.

◆ operator/()

KNumber const KNumber::operator/ ( KNumber const &  arg2) const

Definition at line 550 of file knumber.cpp.

◆ operator<()

bool const KNumber::operator< ( KNumber const &  arg2) const
inline

Definition at line 258 of file knumber.h.

◆ operator<<()

KNumber const KNumber::operator<< ( KNumber const &  arg2) const

Definition at line 613 of file knumber.cpp.

◆ operator<=()

bool const KNumber::operator<= ( KNumber const &  arg2) const
inline

Definition at line 264 of file knumber.h.

◆ operator=()

KNumber const & KNumber::operator= ( KNumber const &  num)

Definition at line 150 of file knumber.cpp.

◆ operator==()

bool const KNumber::operator== ( KNumber const &  arg2) const
inline

Definition at line 249 of file knumber.h.

◆ operator>()

bool const KNumber::operator> ( KNumber const &  arg2) const
inline

Definition at line 255 of file knumber.h.

◆ operator>=()

bool const KNumber::operator>= ( KNumber const &  arg2) const
inline

Definition at line 261 of file knumber.h.

◆ operator>>()

KNumber const KNumber::operator>> ( KNumber const &  arg2) const

Definition at line 628 of file knumber.cpp.

◆ operator|()

KNumber const KNumber::operator| ( KNumber const &  arg2) const

Definition at line 596 of file knumber.cpp.

◆ power()

KNumber const KNumber::power ( KNumber const &  exp) const

Definition at line 476 of file knumber.cpp.

◆ setDefaultFloatOutput()

void KNumber::setDefaultFloatOutput ( bool  flag)
static

Set whether the output of numbers (with KNumber::toTQString) should happen as floating point numbers or not.

This method has in fact only an effect on numbers of type NumType::FractionType, which can be either displayed as fractions or in decimal notation.

The default behavior is not to display fractions in floating point notation.

Definition at line 413 of file knumber.cpp.

◆ setDefaultFloatPrecision()

void KNumber::setDefaultFloatPrecision ( unsigned int  prec)
static

Set the default precision to be at least prec (decimal) digits.

All subsequent initialized floats will use at least this precision, but previously initialized variables are unaffected.

Definition at line 428 of file knumber.cpp.

◆ setDefaultFractionalInput()

void KNumber::setDefaultFractionalInput ( bool  flag)
static

Set whether a number constructed from a TQString should be initialized as a fraction or as a float, e.g.

"1.01" would be treated as 101/100, if this flag is set to true.

The default setting is false.

Definition at line 418 of file knumber.cpp.

◆ setSplitoffIntegerForFractionOutput()

void KNumber::setSplitoffIntegerForFractionOutput ( bool  flag)
static

What a terrible method name!! When displaying a fraction, the default mode gives "nomin/denom".

With this method one can choose to display a fraction as "integer nomin/denom".

Examples: Default representation mode is 47/17, but if flag is true, then the result is 2 13/17.

Definition at line 423 of file knumber.cpp.

◆ sqrt()

KNumber const KNumber::sqrt ( void  ) const

Compute the square root.

If $ x < 0 $ (including $
x=-\infty $), then x.sqrt() returns ErrorType::UndefinedNumber.

If x is an integer or a fraction, then x.sqrt() tries to compute the exact square root. If the square root is not a fraction, then a float with the default precision is returned.

This method works for $ x = \infty $ giving $ \infty $.

Definition at line 457 of file knumber.cpp.

◆ toTQString()

TQString const KNumber::toTQString ( int  width = -1,
int  prec = -1 
) const

Return a TQString representing the KNumber.

Parameters
widthThis number specifies the maximal length of the output, before the method switches to exponential notation and does rounding. For negative numbers, this option is ignored.
precThis parameter controls the number of digits following the decimal point. For negative numbers, this option is ignored.

Definition at line 351 of file knumber.cpp.

◆ type()

KNumber::NumType KNumber::type ( void  ) const

Returns the type of the number, as explained in KNumber::NumType.

Definition at line 116 of file knumber.cpp.

Member Data Documentation

◆ Euler

KNumber const KNumber::Euler
static

Definition at line 69 of file knumber.h.

◆ MinusOne

KNumber const KNumber::MinusOne
static

Definition at line 67 of file knumber.h.

◆ NotDefined

KNumber const KNumber::NotDefined
static

Definition at line 70 of file knumber.h.

◆ One

KNumber const KNumber::One
static

Definition at line 66 of file knumber.h.

◆ Pi

KNumber const KNumber::Pi
static

Definition at line 68 of file knumber.h.

◆ Zero

KNumber const KNumber::Zero
static

Definition at line 65 of file knumber.h.


The documentation for this class was generated from the following files:
  • knumber.h
  • knumber.cpp

kcalc/knumber

Skip menu "kcalc/knumber"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kcalc/knumber

Skip menu "kcalc/knumber"
  • kcalc
  •   knumber
  • superkaramba
Generated for kcalc/knumber by doxygen 1.9.4
This website is maintained by Timothy Pearson.