up: NAT     index Zimbu documentation

CLASS T.nat @public

summary

     

The builtin type nat: 64 bit natural number.

The object methods can be used on a nat variable or value:

 IO.print("0x" .. 1234.toHex())

NOTE: The implementation is incomplete, many methods fall back to the equivalent "int" method.

NOTE: When compiled to Javascript a nat is stored as a float, since Javascript only supports float numbers.

$Size() int @public  Return the number of bytes in a nat.
$ToString() string @public  Return the number in decimal form.
$ToString(format) string @public  Return the number in the specified format.
$Compare(other) int @public  Return < 0 when other is larger than this nat, zero when other is equal to this nat, and > 0 when other is smaller than this nat.
$Equal(other) bool @public  Return TRUE when other is equal to this nat.
$asString() string @public  Return a string with one character that is equal to the number.
$asByteString() byteString @public  Return a byteString with one byte that is equal to the number.
$toQuotedString() string @public  Return the number in decimal form with quotes.
$toHex() string @public  Return a string with the hex representation of the number.
$toHex(minSize) string @public  Return a string with the hex representation of the number.
$toHexUpper() string @public  Return a string with the hex representation of the number.
$toHexUpper(minSize) string @public  Return a string with the hex representation of the number.
$isWhite() bool @public  Return TRUE if the number is a white space character.
$isDigit() bool @public  Return TRUE if the number is a digit character.
$isHexDigit() bool @public  Return TRUE if the number is a hex digit character.
$isAlpha() bool @public  Return TRUE if the number is an alphabetical character.
$isLower() bool @public  Return TRUE if the number is a lower case alphabetical character.
$isUpper() bool @public  Return TRUE if the number is an upper case alphabetical character.
$isWhiteAscii() bool @public  Return TRUE if the number is a white space character.
$isAlphaAscii() bool @public  Return TRUE if the number is an alphabetical ASCII character.
$isLowerAscii() bool @public  Return TRUE if the number is a lower case alphabetical ASCII character.
$isUpperAscii() bool @public  Return TRUE if the number is an upper case alphabetical ASCII character.
$toLowerAscii() nat @public  Return the letter turned in to lower case for ASCII letters.
$toUpperAscii() nat @public  Return letter turned in to upper case for ASCII letters.
$abs() nat @public  Return the absolute value.
$floor() float @public  Return the largest integral value not greater than the value.
$ceil() float @public  Return the smallest integral value not less than the value.
$trunc() float @public  Return the value rounded to integer, toward zero.
$round() float @public  Return the value rounded to integer, away from zero.
$exp() float @public  Return the value of e (the base of natural logarithms) raised to the power of the value.
$log() float @public  Return the natural logarithm of the value.
$log10() float @public  Return the base 10 logarithm of the value.
$sqrt() float @public  Return the nonnegative quare root of the value.
$pow(x) float @public  Return the value raised to the power of x.
$sin() float @public  Return the sine value, using the value as radians.
$sinh() float @public  Return the hyperbolic sine value.
$cos() float @public  Return the cosine value, using the value as radians.
$cosh() float @public  Return the hyperbolic cosine value.
$tan() float @public  Return the tangent value, using the value as radians.
$tanh() float @public  Return the hyperbolic tangent value.
$asin() float @public  Return the principal value of the arc sine of the value.
$acos() float @public  Return the principal value of the arc cosine of the value.
$atan() float @public  Return the principal value of the arc tangent of the value.
$atan2(x) float @public  Return the principal value of the arg tangent of the value divided by x.
 
 

members (alphabetically)

     

FUNC $Compare(nat other) int @public

     

Return < 0 when other is larger than this nat, zero when other is equal to this nat, and > 0 when other is smaller than this nat.

FUNC $Equal(nat other) bool @public

     

Return TRUE when other is equal to this nat.

FUNC $Size() int @public

     

Return the number of bytes in a nat.

Always returns 8, since a nat is 64 bits

FUNC $ToString() string @public

     

Return the number in decimal form.

For example, 1234.ToString() returns "1234".

FUNC $ToString(string format) string @public

     

Return the number in the specified format.

For example, 123.ToString(".5d") returns "00123", 123.ToString("5d") returns " 123".

The format has the fields: [width][.precision]{type}.

{type} can be d for decimal notation or x for hexadecimal notation.

[width] give the minimal width of the result. When the number starts with zero padding is done with zero characters, otherwise with spaces.

[.precision] gives the minimum number of digits that will appear. If the value requires fewer digits it is padded on the left with zeroes. When the precision is zero and the value is zero the result is an empty string.

FUNC $abs() nat @public

     

Return the absolute value.

This is a No-op, only provided for consistency.

FUNC $acos() float @public

     

Return the principal value of the arc cosine of the value.

Same as T.float.acos().

FUNC $asByteString() byteString @public

     

Return a byteString with one byte that is equal to the number.

Same as T.int.asString()

FUNC $asString() string @public

     

Return a string with one character that is equal to the number.

Same as T.int.asString()

FUNC $asin() float @public

     

Return the principal value of the arc sine of the value.

Same as T.float.asin().

FUNC $atan() float @public

     

Return the principal value of the arc tangent of the value.

Same as T.float.atan().

FUNC $atan2(float x) float @public

     

Return the principal value of the arg tangent of the value divided by x.

Same as T.float.atan2().

FUNC $ceil() float @public

     

Return the smallest integral value not less than the value.

Same as T.float.ceil().

FUNC $cos() float @public

     

Return the cosine value, using the value as radians.

Same as T.float.cos().

FUNC $cosh() float @public

     

Return the hyperbolic cosine value.

Same as T.float.cosh().

FUNC $exp() float @public

     

Return the value of e (the base of natural logarithms) raised to the power of the value.

Same as T.float.exp().

FUNC $floor() float @public

     

Return the largest integral value not greater than the value.

Same as T.float.floor().

FUNC $isAlpha() bool @public

     

Return TRUE if the number is an alphabetical character.

That is for 'a' to 'z' and 'A' to 'Z'. TODO: Unicode support

FUNC $isAlphaAscii() bool @public

     

Return TRUE if the number is an alphabetical ASCII character.

That is for 'a' to 'z' and 'A' to 'Z'

FUNC $isDigit() bool @public

     

Return TRUE if the number is a digit character.

That is for '0' (48, 0x30) up to '9' (57, 0x39).

FUNC $isHexDigit() bool @public

     

Return TRUE if the number is a hex digit character.

That is for '0' (48, 0x30) up to '9' (57, 0x39), 'a' up to 'f' and 'A' up to 'F'.

FUNC $isLower() bool @public

     

Return TRUE if the number is a lower case alphabetical character.

That is for 'a' to 'z'. TODO: Unicode support

FUNC $isLowerAscii() bool @public

     

Return TRUE if the number is a lower case alphabetical ASCII character.

That is for 'a' to 'z'.

FUNC $isUpper() bool @public

     

Return TRUE if the number is an upper case alphabetical character.

That is for 'A' to 'Z'. TODO: Unicode support

FUNC $isUpperAscii() bool @public

     

Return TRUE if the number is an upper case alphabetical ASCII character.

That is for 'A' to 'Z'

FUNC $isWhite() bool @public

     

Return TRUE if the number is a white space character.

That is for space, tab, control characters, etc.

FUNC $isWhiteAscii() bool @public

     

Return TRUE if the number is a white space character.

That is for space, tab and control characters.

FUNC $log() float @public

     

Return the natural logarithm of the value.

Same as T.float.log().

FUNC $log10() float @public

     

Return the base 10 logarithm of the value.

Same as T.float.log10().

FUNC $pow(float x) float @public

     

Return the value raised to the power of x.

Same as T.float.pow().

FUNC $round() float @public

     

Return the value rounded to integer, away from zero.

Same as T.float.round().

FUNC $sin() float @public

     

Return the sine value, using the value as radians.

Same as T.float.sin().

FUNC $sinh() float @public

     

Return the hyperbolic sine value.

Same as T.float.sinh().

FUNC $sqrt() float @public

     

Return the nonnegative quare root of the value.

Same as T.float.sqrt().

FUNC $tan() float @public

     

Return the tangent value, using the value as radians.

Same as T.float.tan().

FUNC $tanh() float @public

     

Return the hyperbolic tangent value.

Same as T.float.tanh().

FUNC $toHex() string @public

     

Return a string with the hex representation of the number.

Uses lower case letters

For example: 123.toHex() returns "7b".

FUNC $toHex(int minSize) string @public

     

Return a string with the hex representation of the number.

Uses lower case letters 'a' to 'f'.

minSize is the minimum size of the string, leading zeroes are added when needed. The string will get longer when needed.

For example: 123.toHex(4) returns "007b".

FUNC $toHexUpper() string @public

     

Return a string with the hex representation of the number.

Uses upper case letters 'A' to 'F'.

For example: 123.toHex() returns "7B".

FUNC $toHexUpper(int minSize) string @public

     

Return a string with the hex representation of the number.

Uses upper case letters 'A' to 'F'.

minSize is the minimum size of the string, leading zeroes are added when needed. The string will get longer when needed.

For example: 123.toHex(4) returns "007B".

FUNC $toLowerAscii() nat @public

     

Return the letter turned in to lower case for ASCII letters.

Only works for ASCII, thus 'A' - 'Z' becomes 'a' - 'z'. All other characters are returned unchanged.

FUNC $toQuotedString() string @public

     

Return the number in decimal form with quotes.

For example, 1000000.toQuotedString() returns "1'000'000".

FUNC $toUpperAscii() nat @public

     

Return letter turned in to upper case for ASCII letters.

Only works for ASCII, thus 'a' - 'z' becomes 'A' - 'Z'. All other characters are returned unchanged.

FUNC $trunc() float @public

     

Return the value rounded to integer, toward zero.

Same as T.float.trunc().

license

      Copyright 2014 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0