1
0
Fork 0
forked from fun/fun

More math opcode Fun. (0.37.44)

This commit is contained in:
Johannes Findeisen 2026-01-03 04:10:11 +01:00
commit 4a6903e58a
16 changed files with 546 additions and 2 deletions

View file

@ -0,0 +1,32 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2026 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-03
*/
// Demo of fmin(x,y) / fmax(x,y) float-aware min/max with C99 NaN handling
print("=== math fmin/fmax demo start ===")
print("fmin(3.2, 4) -> " + to_string(fmin(3.2, 4))) // 3.2
print("fmax(3.2, 4) -> " + to_string(fmax(3.2, 4))) // 4
print("fmin(-5, -2.5) -> " + to_string(fmin(-5, -2.5))) // -5
print("fmax(-5, -2.5) -> " + to_string(fmax(-5, -2.5))) // -2.5
print("=== math fmin/fmax demo end ===")
/* Expected output:
=== math fmin/fmax demo start ===
fmin(3.2, 4) -> 3.2000000000000002
fmax(3.2, 4) -> 4
fmin(-5, -2.5) -> -5
fmax(-5, -2.5) -> -2.5
=== math fmin/fmax demo end ===
*/

35
examples/math_gcd_lcm.fun Normal file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2026 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-03
*/
print("=== math gcd/lcm demo start ===")
print("gcd(48,18) -> " + to_string(gcd(48,18))) // 6
print("gcd(0,5) -> " + to_string(gcd(0,5))) // 5
print("gcd(-21,6) -> " + to_string(gcd(-21,6))) // 3
print("lcm(21,6) -> " + to_string(lcm(21,6))) // 42
print("lcm(0,5) -> " + to_string(lcm(0,5))) // 0
print("lcm(-4,6) -> " + to_string(lcm(-4,6))) // 12
print("=== math gcd/lcm demo end ===")
/* Expected output (values):
=== math gcd/lcm demo start ===
gcd(48,18) -> 6
gcd(0,5) -> 5
gcd(-21,6) -> 3
lcm(21,6) -> 42
lcm(0,5) -> 0
lcm(-4,6) -> 12
=== math gcd/lcm demo end ===
*/

38
examples/math_isqrt.fun Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2026 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-03
*/
print("=== math isqrt demo start ===")
print("isqrt(-4) -> " + to_string(isqrt(-4))) // 0 (non-negative only)
print("isqrt(0) -> " + to_string(isqrt(0))) // 0
print("isqrt(1) -> " + to_string(isqrt(1))) // 1
print("isqrt(2) -> " + to_string(isqrt(2))) // 1
print("isqrt(3) -> " + to_string(isqrt(3))) // 1
print("isqrt(4) -> " + to_string(isqrt(4))) // 2
print("isqrt(15) -> " + to_string(isqrt(15))) // 3
print("isqrt(16) -> " + to_string(isqrt(16))) // 4
print("=== math isqrt demo end ===")
/* Expected output (values):
=== math isqrt demo start ===
isqrt(-4) -> 0
isqrt(0) -> 0
isqrt(1) -> 1
isqrt(2) -> 1
isqrt(3) -> 1
isqrt(4) -> 2
isqrt(15) -> 3
isqrt(16) -> 4
=== math isqrt demo end ===
*/

32
examples/math_sign.fun Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2026 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-03
*/
print("=== math sign demo start ===")
print("sign(-5) -> " + to_string(sign(-5))) // -1
print("sign(0) -> " + to_string(sign(0))) // 0
print("sign(7) -> " + to_string(sign(7))) // 1
print("sign(-0.0) -> " + to_string(sign(-0.0))) // 0
print("sign(3.14) -> " + to_string(sign(3.14))) // 1
print("=== math sign demo end ===")
/* Expected output (values):
=== math sign demo start ===
sign(-5) -> -1
sign(0) -> 0
sign(7) -> 1
sign(-0.0) -> 0
sign(3.14) -> 1
=== math sign demo end ===
*/