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

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.

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


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.8.13
This website is maintained by Timothy Pearson.