diff options
| author | PgBiel <9021226+PgBiel@users.noreply.github.com> | 2024-09-26 08:39:37 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-26 11:39:37 +0000 |
| commit | 320c28844f4e2686ab1bedfc507c9c7babafed63 (patch) | |
| tree | 1fc37697db5d7bf615f55700589668d862ea342e /tests/suite/scripting | |
| parent | a69ada7889c5c5996d0660401e981b6baac14a83 (diff) | |
Fixed-point decimal type (#4900)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'tests/suite/scripting')
| -rw-r--r-- | tests/suite/scripting/ops.typ | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/tests/suite/scripting/ops.typ b/tests/suite/scripting/ops.typ index e0c94e02..d17c0117 100644 --- a/tests/suite/scripting/ops.typ +++ b/tests/suite/scripting/ops.typ @@ -8,7 +8,7 @@ // Test math operators. // Test plus and minus. -#for v in (1, 3.14, 12pt, 45deg, 90%, 13% + 10pt, 6.3fr) { +#for v in (1, 3.14, decimal("12.43"), 12pt, 45deg, 90%, 13% + 10pt, 6.3fr) { // Test plus. test(+v, v) @@ -60,6 +60,7 @@ // Mathematical identities. #let nums = ( 1, 3.14, + decimal("12.45"), 12pt, 3em, 12pt + 3em, 45deg, 90%, @@ -76,12 +77,12 @@ test(v - v, 0 * v) test(v + v, 2 * v) - // Integer addition does not give a float. - if type(v) != int { + // Integer or decimal addition does not give a float. + if type(v) not in (int, decimal) { test(v + v, 2.0 * v) } - if type(v) != relative and ("pt" not in repr(v) or "em" not in repr(v)) { + if type(v) not in (relative, decimal) and ("pt" not in repr(v) or "em" not in repr(v)) { test(v / v, 1.0) } } @@ -112,6 +113,46 @@ } } +--- ops-binary-decimal --- +// Addition. +#test(decimal("40.1") + decimal("13.2"), decimal("53.3")) +#test(decimal("12.34330") + decimal("45.96670"), decimal("58.31000")) +#test(decimal("451113.111111111111111111111") + decimal("23.222222222222222222324"), decimal("451136.333333333333333333435")) + +// Subtraction. +#test(decimal("40.1") - decimal("13.2"), decimal("26.9")) +#test(decimal("12.34330") - decimal("45.96670"), decimal("-33.62340")) +#test(decimal("1234.111111111111111111111") - decimal("0.222222222222222222324"), decimal("1233.888888888888888888787")) + +// Multiplication. +#test(decimal("40.5") * decimal("9.5"), decimal("384.75")) +#test(decimal("-0.1234567890123456789012345678") * decimal("-2.0"), decimal("0.2469135780246913578024691356")) + +// Division. +#test(decimal("1.0") / decimal("7.0"), decimal("0.1428571428571428571428571429")) +#test(decimal("9999991.6666") / decimal("3.0"), decimal("3333330.5555333333333333333333")) +#test(decimal("3253452.4034029359598214312040") / decimal("-49293591.4039493929532"), decimal("-0.0660015290170614346071165643")) + +--- ops-binary-decimal-int --- +// Operations between decimal and integer. +#test(decimal("2359.123456789123456789001234") + 2, decimal("2361.123456789123456789001234")) +#test(decimal("2359.123456789123456789001234") - 2, decimal("2357.123456789123456789001234")) +#test(decimal("2359.123456789123456789001234") * 2, decimal("4718.246913578246913578002468")) +#test(decimal("2359.123456789123456789001234") / 2, decimal("1179.561728394561728394500617")) + +--- ops-binary-decimal-multiplication-division-imprecision --- +// Test digit truncation by multiplication and division. +#test(decimal("0.7777777777777777777777777777") / 1000, decimal("0.0007777777777777777777777778")) +#test(decimal("0.7777777777777777777777777777") * decimal("0.001"), decimal("0.0007777777777777777777777778")) + +--- ops-add-too-large-decimal --- +// Error: 3-47 value is too large +#(decimal("79228162514264337593543950335") + 1) + +--- ops-subtract-too-large-decimal --- +// Error: 3-48 value is too large +#(decimal("-79228162514264337593543950335") - 1) + --- ops-multiply-inf-with-length --- // Test that multiplying infinite numbers by certain units does not crash. #(float("inf") * 1pt) @@ -164,6 +205,8 @@ #test((:) == (a: 1), false) #test((a: 2 - 1.0, b: 2) == (b: 2, a: 1), true) #test("a" != "a", false) +#test(decimal("1.234") == decimal("1.23400000000"), true) +#test(235 == decimal("235.0"), true) // Functions compare by identity. #test(test == test, true) @@ -202,6 +245,10 @@ #test(() >= (), true) #test(() <= (1,), true) #test((1,) <= (), false) +#test(decimal("123.0000000000000000000000001") > decimal("123.0"), true) +#test(decimal("123.5") < decimal("122.444"), false) +#test(decimal("459.9999999999999999999999999") < 460, true) +#test(decimal("128.50") > 460, false) --- ops-in --- // Test `in` operator. |
