Skip to main content
🚨 重要提示

本项目目前仍处于早期开发阶段,核心功能尚未完全实现,语法规范和工具链仍在持续完善中。

Numeric Type

🐳Type Overview​

Integer & Decimal Types (Number Type)​

TypeSize
(bytes)
Description
numbervariableCan represent an integer or decimal
integervariableHigh-precision integer
decimalvariableHigh-precision floating-point

🏅Syntax Examples​

  • Define a number:
number num = 2025;
num.isInfinity() // result: false
num.isFinite() // result: true
num.isPositive() // result: true
num.isNegative() // result: false
num.isNaN() // result: false
num.isInteger() // result: true
num.isDecimal() // result: false
num.toString() // result: "2025"

number decimalNum = -.123456; // -0.123456
decimalNum.isInfinity() // result: false
decimalNum.isFinite() // result: true
decimalNum.isPositive() // result: false
decimalNum.isNegative() // result: true
num.isNaN() // result: false
num.isInteger() // result: false
num.isDecimal() // result: true
num.toString() // result: "-0.123456"

number anOtherDecimalNum = 2f; // Ending with f can also denote a floating-point number, equivalent to 2.0, 2.00, etc.

number positiveFinity = Infinity
positiveFinity.isInfinity() // result: true
positiveFinity.isFinite() // result: false
positiveFinity.isPositive() // result: true
positiveFinity.isNegative() // result: false
positiveFinity.isNaN() // result: false
positiveFinity.isInteger() // result: false
positiveFinity.isDecimal() // result: false
positiveFinity.toString() // result: "+Infinity"

number negativeFinity = -Infinity
negativeFinity.isInfinity() // result: true
negativeFinity.isFinite() // result: false
negativeFinity.isPositive() // result: false
negativeFinity.isNegative() // result: true
negativeFinity.isNaN() // result: false
negativeFinity.isInteger() // result: false
negativeFinity.isDecimal() // result: false
negativeFinity.toString() // result: "-Infinity"

number notANumber = NaN;
notANumber.isInfinity() // result: false
notANumber.isFinite() // result: false
notANumber.isPositive() // result: false
notANumber.isNegative() // result: false
notANumber.isNaN() // result: true
notANumber.isInteger() // result: false
notANumber.isDecimal() // result: false
negativeFinity.toString() // result: "NaN"
  • Number comparison:
1 == 1.0 // result: true
  • Convert a number to a string:
12.toString(10) // "1"
12.toString(10) // "1"
12.00.toString(10) // "12.0"
NaN.toString() // "NaN"

// TODO: keep a given number of decimal places, keep a given number of significant figures
// TODO: convert scientific notation to a string
  • Convert a string to a number:
"Infinity".toNumber() // result: Infinity
"+Infinity".toNumber() // result: Infinity
"-Infinity".toNumber() // result: -Infinity

"infinity".toNumber() // result: NaN
  • Scientific notation
// TODO
  • Rounding:
// TODO
  • Modulo:
-1 % 5 // result: 4
-1 % -5 // result: -1
1 % -5 // result: -4
Note

The result of the modulo of a negative number may differ across programming languages. For example, for -1 mod 5, the result is -1 in Java and 4 in Python.

  • Integer division:
Math.integerDivision(-1, 5) // result: -1
-1.integerDivision(5) // result: 0.2

-1 / 5 // result: -0.2
Math.division(-1, 5) // result: -0.2
  • Addition, subtraction, multiplication, division:
1.1 + 2 // result: 3.1

3 - 5.2 // -2.2

6 * 8 // result: 48

1 / 3 // result: 0.3333333333333333
2 / 3 // result: 0.6666666666666666
  • Absolute value:
-1.abs() // result: 1
Math.abs(-1) // result: 1
  • Get the integer part
123.456.integerPart() // 123
123.456.decimalPart() // 0.456

-123.456.integerPart() // -123
-123.456.decimalPart() // -0.456

Floating-point Types​

TypeSize
(bytes)
RangeMin value
object.MIN_VALUE
Max value
object.MAX_VALUE
Description
float4 byte[2-149, (2-2-23)·2127]1.4e-45
(0x1.0p-126)
3.4028235e+38
(0x1.FFFFFE0000000p+127)
32-bit floating-point
+float4 byteto be confirmedto be confirmedto be confirmed32-bit non-negative floating-point
-float4 byteto be confirmedto be confirmedto be confirmed32-bit non-positive floating-point
double8 byte[2-1074, (2-2-52)·21023]4.9e-324
(0x0.0000000000001p-1022)
1.7976931348623157e+308
(0x1.FFFFFFFFFFFFFp+1023)
64-bit floating-point
+double8 byteto be confirmedto be confirmedto be confirmed64-bit non-negative floating-point
-double8 byteto be confirmedto be confirmedto be confirmed64-bit non-positive floating-point

General Numeric Types​

TypeDescription
numberSupports storing both integers and decimals. For scenarios where execution efficiency is not critical, use this type to reduce mental overhead
integerHigh-precision integer (can represent integers of arbitrary magnitude exactly)
decimalHigh-precision floating-point (can represent decimals of arbitrary length exactly). Floating-point operations output a 17-digit-long result, but only 15 digits are accurate

References​

IEEE 754 Standard​