Number Class

The Number class handles limited-precision signed base 10 numbers. A Number guarantees 38 decimal digits of precision. All positive numbers in the range displayed here can be represented to a full 38-digit precision:

10^-130

and

9.99999999999999999999999999999999999999*10^125

The range of representable negative numbers is symmetrical.

The number zero can be represented exactly. Also, Oracle numbers have representations for positive and negative infinity. These are generally used to indicate overflow.

The internal storage type is opaque and private. Scale is not preserved when Number instances are created.

Number does not support the concept of NaN and is not IEEE-754-85 compliant. Number does support +Infinity and -Infinity.

Objects from the Number class can be used as standalone class objects in client side numerical computations. They can also be used to fetch from and set to the database.

Example 12-10 How to Retrieve and Use a Number Obect

This example demonstrates a Number column value being retrieved from the database, a bind using a Number object, and a comparison using a standalone Number object.

The nls parameters string. If nlsParam is specified, this determines the nls parameters to be used for the conversion. If nlsParam is not specified, the nls parameters are picked up from envp.

hypCos()

This method returns the hypercosine of the Number object.

Syntax

const Number hypCos() const;

hypSin()

This method returns the hypersine of the Number object.

Syntax

const Number hypSin() const;

hypTan()

This method returns the hypertangent of the Number object.

Syntax

const Number hypTan() const;

intPower()

This method returns a Number whose value is the number object raised to the power of the value specified.

Syntax

const Number intPower(
int val) const;

Parameter

Description

val

Power to which the number is raised.

isNull()

This method tests whether the Number object is NULL. If the Number object is NULL, then TRUE is returned; otherwise, FALSE is returned.

Syntax

bool isNull() const;

ln()

This method returns the natural logarithm of the Number object.

Syntax

const Number ln() const;

log()

This method returns the logarithm of the Number object with the base provided by the parameter specified.

Syntax

const Number log(
const Number &val) const;

Parameter

Description

val

The base to be used in the logarithm calculation.

operator++()

Unary operator++(). This is a postfix operator.

Syntax

Description

Number& operator++();

This method returns the Number object incremented by 1.

const Number operator++(
int incr);

This method returns the Number object incremented by the integer specified.

Parameter

Description

incr

The number by which the Number object is incremented.

operator--()

Unary operator--(). This is a prefix operator.

Syntax

Description

Number& operator--();

This method returns the Number object decremented by 1.

const Number operator--(
int decr);

This method returns the Number object decremented by the integer specified.

Parameter

Description

decr

The number by which the Number object is decremented.

operator*()

This method returns the product of the parameters specified.

Syntax

Number operator*(
const Number &first,

const Number &second);

Parameter

Description

first

First multiplicand.

second

Second multiplicand.

operator/()

This method returns the quotient of the parameters specified.

Syntax

Number operator/(
const Number &dividend,
const Number &divisor);

Parameter

Description

dividend

The number to be divided.

divisor

The number by which to divide.

operator%()

This method returns the remainder of the division of the parameters specified.

Syntax

Number operator%(
const Number &dividend,
const Number &divider);

Parameter

Description

dividend

The number to be divided.

divizor

The number by which to divide.

operator+()

This method returns the sum of the parameters specified.

Syntax

Number operator+(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be added.

second

Second number to be added.

operator-()

Unary operator-(). This method returns the negated value of the Number object.

Syntax

const Number operator-();

operator-()

This method returns the difference between the parameters specified.

Syntax

Number operator-(
const Number &subtrahend,
const Number &subtractor);

Parameter

Description

subtrahend

The number to be reduced.

subtractor

The number to be subtracted.

operator<()

This method checks whether the first parameter specified is less than the second parameter specified. If the first parameter is less than the second parameter, then TRUE is returned; otherwise, FALSE is returned. If either parameter is equal to infinity, then FALSE is returned.

Syntax

bool operator<(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator<=()

This method checks whether the first parameter specified is less than or equal to the second parameter specified. If the first parameter is less than or equal to the second parameter, then TRUE is returned; otherwise, FALSE is returned. If either parameter is equal to infinity, then FALSE is returned.

Syntax

bool operator<=(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator>()

This method checks whether the first parameter specified is greater than the second parameter specified. If the first parameter is greater than the second parameter, then TRUE is returned; otherwise, FALSE is returned. If either parameter is equal to infinity, then FALSE is returned.

Syntax

bool operator>(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator>=()

This method checks whether the first parameter specified is greater than or equal to the second parameter specified. If the first parameter is greater than or equal to the second parameter, then TRUE is returned; otherwise, FALSE is returned. If either parameter is equal to infinity, then FALSE is returned.

Syntax

bool operator>=(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator==()

This method checks whether the parameters specified are equal. If the parameters are equal, then TRUE is returned; otherwise, FALSE is returned. If either parameter is equal to +infinity or -infinity, then FALSE is returned.

Syntax

bool operator==(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator!=()

This method checks whether the first parameter specified is equal to the second parameter specified. If the parameters are not equal, TRUE is returned; otherwise, FALSE is returned.

Syntax

bool operator!=(
const Number &first,
const Number &second);

Parameter

Description

first

First number to be compared.

second

Second number to be compared.

operator=()

This method assigns the value of the parameter specified to the Number object.

Syntax

Number& operator=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator*=()

This method multiplies the Number object by the parameter specified, and assigns the product to the Number object.

Syntax

Number& operator*=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator/=()

This method divides the Number object by the parameter specified, and assigns the quotient to the Number object.

Syntax

Number& operator/=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator%=()

This method divides the Number object by the parameter specified, and assigns the remainder to the Number object.

Syntax

Number& operator%=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator+=()

This method adds the Number object and the parameter specified, and assigns the sum to the Number object.

Syntax

Number& operator+=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator-=()

This method subtracts the parameter specified from the Number object, and assigns the difference to the Number object.

Syntax

Number& operator-=(
const Number &num);

Parameter

Description

num

A parameter of type Number.

operator char()

This method returns the value of the Number object converted to a native char.

Syntax

operator char() const;

operator signed char()

This method returns the value of the Number object converted to a native signed char.

Syntax

operator signed char() const;

operator double()

This method returns the value of the Number object converted to a native double.

Syntax

operator double() const;

operator float()

This method returns the value of the Number object converted to a native float.

Syntax

operator float() const;

operator int()

This method returns the value of the Number object converted to a native int.

Syntax

operator int() const;

operator long()

This method returns the value of the Number object converted to a native long.

Syntax

operator long() const;

operator long double()

This method returns the value of the Number object converted to a native long double.

Syntax

operator long double() const;

operator short()

This method returns the value of the Number object converted to a native short integer.

Syntax

operator short() const;

operator unsigned char()

This method returns the value of the Number object converted to a native unsigned char.

Syntax

operator unsigned char() const;

operator unsigned int()

This method returns the value of the Number object converted to a native unsigned int.

Syntax

operator unsigned int() const;

operator unsigned long()

This method returns the value of the Number object converted to a native unsigned long.

Syntax

operator unsigned long() const;

operator unsigned short()

This method returns the value of the Number object converted to a native unsigned short integer.

Syntax

operator unsigned short() const;

power()

This method returns the value of the Number object raised to the power of the value provided by the parameter specified.

Syntax

const Number power(
const Number &val) const;

Parameter

Description

val

The power to which the number has to be raised.

prec()

This method returns the value of the Number object rounded to the digits of precision provided by the parameter specified.

Syntax

const Number prec(
int digits) const;

Parameter

Description

digits

The number of digits of precision.

round()

This method returns the value of the Number object rounded to the decimal place provided by the parameter specified.

Syntax

const Number round(
int decPlace) const;

Parameter

Description

decPlace

The number of digits to the right of the decimal point.

setNull()

This method sets the value of the Number object to NULL.

Syntax

void setNull();

shift()

This method returns the Number object multiplied by 10 to the power provided by the parameter specified.

Syntax

const Number shift(
int val) const;

Parameter

Description

val

An integer value.

sign()

This method returns the sign of the value of the Number object. If the Number object is negative, then create a Date object using integer parameters is returned. If the Number object is equal to 0, then create a Date object using integer parameters is returned. If the Number object is positive, then 1 is returned.

Syntax

const int sign() const;

sin()

This method returns the sin of the Number object.

Syntax

const Number sin() const;

squareroot()

This method returns the square root of the Number object.

Syntax

const Number squareroot() const;

tan()

This method returns the tangent of the Number object.

Syntax

const Number tan() const;

toBytes()

This method converts the Number object into a Bytes object. The bytes representation is assumed to be in length excluded format, that is, the Byte.length() method gives the length of valid bytes and the 0th byte is the exponent byte.

Syntax

Bytes toBytes() const;

toText()

Convert the Number object to a formatted string or UString based on the parameters specified.