# Package: Kernel-Numbers

## Class: Number

### Introduction

**Environment: ****container**

A common abstract superclass for all Number implementations. It is the superclass of all classes that represent numbers, for example Integer, Float, and Fraction, etc. The binary operators `+`

,`=`

,`*`

,`/`

are defined for all numbers, so we can do arithmetic.

For example:

We support traditional arithmetic precedence, so the above expression is equivalent to:

### Class Method

#### Category: instance creation

- Create a new number object. The default value is 1.**new**

### Instance Method

#### Category: arithmetic

- Multiply two numbers.*****

- Add two numbers.**+**

- Subtract two numbers.**-**

- Divide two numbers.**/**

- answer a number that is the absolute value (positive magnitude) of the receiver.**abs**For example:

- Answer whether the receiver is an even number.**even**For example:

- answer a Number that is the floor value (positive magnitude) of the receiver.**floor**For example:

- Answer whether the receiver is an odd number.**odd**For example:

- answer the receiver raised to aNumber.**raisedTo:**For example:

#### Category: comparing

- Compare the receiver with the argument and answer with true if the receiver is less than the argument. Otherwise answer false.**<**

- Compare the receiver with the argument and answer true if the receiver is less than or equal to the argument. Otherwise answer false.**<=**

- Compare the receiver with the argument and answer true if the receiver is equal to the argument. Otherwise answer false.**=**

- answer whether the receiver sorts after aString. The collation order is simple ascii (with case differences).**>**

- Compare the receiver with the argument and answer true if the receiver is greater than or equal to the argument. Otherwise answer false.**>=**

- Test if object is float.**isFloat**For example:

- Test if object is integer.**isInteger**For example:

- Test if number is zero.**isZero**For example:

- Answer the greater of the two numbers in arguments**max:**For example:

- Answer the lesser of the two numbers in arguments**min:**For example:

- Test if number is negative.**negative**For example:

- Test if number is positive.**positive**For example:

- test if number is greater than zero.**strictlyPositive**For example:

#### Category: controlling

- Evaluate the argument, aBlock, the number of times represented by the receiver.**timesRepeat:**For example:

- Normally compiled in-line, and therefore not overridable.**to:**Build an array of the integers from the receiver to the argument, aNumber, and evaluate aBlock with each of the integers as the argument.

For example:

- Normally compiled in-line, and therefore not overridable. Evaluate aBlock for each element of the interval (self to: stop by: step).**to:by:do:**For example:

- Normally compiled in-line, and therefore not overridable. Evaluate aBlock for each element of the interval (self to: stop by: 1).**to:do:**For example:

#### Category: converting

- Answer the Character whose value is the receiver.**asCharacter**For example:

- The custom numeric format specifiers**asCustomNumber:**The custom numeric format specifiers answer a string that is the receiver formatted according to the format string. The format string is a string that contains a number of placeholders that are replaced by the corresponding values of the receiver.

Here is a list of available format String.

[

`0`

] ** Zero placeholder**. Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.**Example:**[

`#`

]**Digit placeholder**. Replaces the “#” symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.No digit appears in the result string if the corresponding digit in the input string is a non-significant 0.

**Example:**`.`

[

`.`

]**Decimal point**. Determines the location of the decimal separator in the result string.**Example:**[

`,`

]**Group separator and number scaling**. Can be used as both a group separator (also known as a thousand separator) and a number scaling specifier.As a

**group separator**, it inserts a localized group separator character between each group.As a

**number scaling specifier**, it divides a number by 1000 for each comma specified.

To specify a group separator, place one or more commas between two digit placeholders (0 or #) that format the integral digits of a number. This results in a group separator character being inserted between each number group in the integral part of the output.

To specify a number scaling specifier, place one or more commas immediately to the left of the explicit or implicit decimal point.

**Example - As a Group Separator:****Example – As a Number Scaling Specifier**:**Example – As Both**:[

`%`

]**Percentage placeholder**. Multiplies a number by 100 and inserts a localized percentage symbol in the result string.**Example:**[

`‰`

]**Per mille placeholder**. Multiplies a number by 1000 and inserts a localized per mille symbol in the result string.**Example:**[

`E0`

`E+0`

`E-0`

`e0`

`e+0`

`e-0`

]**Exponential notation**. If followed by at least one zero (`0`

), formats the result using exponential notation. The case (`E`

or`e`

) indicates the case of the exponent symbol in the result string. The number of zeros following the`E`

or`e`

character determines the minimum number of digits in the exponent. A plus sign (`+`

) indicates that a sign character always precedes the exponent. A minus sign (`-`

) indicates that a sign character precedes only negative exponents.**Example:**[

`\`

]**Escape character**. Causes the next character to be interpreted as a literal rather than as a custom format specifier.**Example**:[

`'string'`

`"string"`

]**Literal string delimiter**. Indicates that the enclosed characters should be copied to the result string unchanged.**Example**:[

`;`

, Other]**All other characters.**The character is copied to the result string unchanged.**Example**:

- Answer the number as a float data type.**asFloat**For example:

- return the integer present in the receiver, or nil. In case of float, returns the integer part.**asInteger**For example:

- Converts a number into a string.**asString**For example:

- Answer the number, rounded to the nearest multiple of the other argument.**roundTo:**For example:

- Answer the number, truncated to the nearest multiple of the other argument.**truncateTo:**For example:

#### Category: math

- Answer the cosine of the number. The argument is assumed to be in radians.**cos**For example:

- Answer the e raised to the number.**exp**For example:

- Answer the natural log (base e) of the number.**ln**For example:

- Answer the log of the number, base of number in second argument.**log:**For example:

- Answer the sine of the number. The angle is assumed to be in radians.**sin**For example:

- Answer the square root of the number.**sqrt**For example:

- Answer the square of the number.**squared**For example:

- Answer the tangent of the number. The angle is assumed to be in radians.**tan**For example:

- Answer the hyperbolic tangent of the number. The angle is assumed to be in radians.**tanh**For example:

#### Category: testing

- Answer whether the receiver can be accessed by a numeric index with #at:/#at:put:.**isSequenceable**

Last updated