Added some math opcodes. (0.37.42)
This commit is contained in:
parent
2a20b6f01a
commit
194c06e4aa
14 changed files with 413 additions and 2 deletions
36
examples/math_ceil.fun
Normal file
36
examples/math_ceil.fun
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/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 C99-like ceil(x)
|
||||
|
||||
print("=== math ceil demo start ===")
|
||||
|
||||
print("ceil(3.2) -> " + to_string(ceil(3.2))) // 4
|
||||
print("ceil(3.0) -> " + to_string(ceil(3.0))) // 3
|
||||
print("ceil(-3.2) -> " + to_string(ceil(-3.2))) // -3
|
||||
print("ceil(-3.0) -> " + to_string(ceil(-3.0))) // -3
|
||||
print("ceil(0.5) -> " + to_string(ceil(0.5))) // 1
|
||||
print("ceil(-0.5) -> " + to_string(ceil(-0.5))) // 0
|
||||
|
||||
print("=== math ceil demo end ===")
|
||||
|
||||
/* Expected output (values):
|
||||
=== math ceil demo start ===
|
||||
ceil(3.2) -> 4
|
||||
ceil(3.0) -> 3
|
||||
ceil(-3.2) -> -3
|
||||
ceil(-3.0) -> -3
|
||||
ceil(0.5) -> 1
|
||||
ceil(-0.5) -> 0
|
||||
=== math ceil demo end ===
|
||||
*/
|
||||
36
examples/math_floor.fun
Normal file
36
examples/math_floor.fun
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/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 C99-like floor(x)
|
||||
|
||||
print("=== math floor demo start ===")
|
||||
|
||||
print("floor(3.7) -> " + to_string(floor(3.7))) // 3
|
||||
print("floor(3.0) -> " + to_string(floor(3.0))) // 3
|
||||
print("floor(-3.2) -> " + to_string(floor(-3.2))) // -4
|
||||
print("floor(-3.0) -> " + to_string(floor(-3.0))) // -3
|
||||
print("floor(0.5) -> " + to_string(floor(0.5))) // 0
|
||||
print("floor(-0.5) -> " + to_string(floor(-0.5))) // -1
|
||||
|
||||
print("=== math floor demo end ===")
|
||||
|
||||
/* Expected output (values):
|
||||
=== math floor demo start ===
|
||||
floor(3.7) -> 3
|
||||
floor(3.0) -> 3
|
||||
floor(-3.2) -> -4
|
||||
floor(-3.0) -> -3
|
||||
floor(0.5) -> 0
|
||||
floor(-0.5) -> -1
|
||||
=== math floor demo end ===
|
||||
*/
|
||||
36
examples/math_round.fun
Normal file
36
examples/math_round.fun
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/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 C99-like round(x) — half away from zero
|
||||
|
||||
print("=== math round demo start ===")
|
||||
|
||||
print("round(3.2) -> " + to_string(round(3.2))) // 3
|
||||
print("round(3.5) -> " + to_string(round(3.5))) // 4
|
||||
print("round(3.8) -> " + to_string(round(3.8))) // 4
|
||||
print("round(-3.2) -> " + to_string(round(-3.2))) // -3
|
||||
print("round(-3.5) -> " + to_string(round(-3.5))) // -4
|
||||
print("round(-3.8) -> " + to_string(round(-3.8))) // -4
|
||||
|
||||
print("=== math round demo end ===")
|
||||
|
||||
/* Expected output (values):
|
||||
=== math round demo start ===
|
||||
round(3.2) -> 3
|
||||
round(3.5) -> 4
|
||||
round(3.8) -> 4
|
||||
round(-3.2) -> -3
|
||||
round(-3.5) -> -4
|
||||
round(-3.8) -> -4
|
||||
=== math round demo end ===
|
||||
*/
|
||||
36
examples/math_trunc.fun
Normal file
36
examples/math_trunc.fun
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/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 C99-like trunc(x) — rounds toward zero
|
||||
|
||||
print("=== math trunc demo start ===")
|
||||
|
||||
print("trunc(3.7) -> " + to_string(trunc(3.7))) // 3
|
||||
print("trunc(3.0) -> " + to_string(trunc(3.0))) // 3
|
||||
print("trunc(-3.7) -> " + to_string(trunc(-3.7))) // -3
|
||||
print("trunc(-3.0) -> " + to_string(trunc(-3.0))) // -3
|
||||
print("trunc(0.5) -> " + to_string(trunc(0.5))) // 0
|
||||
print("trunc(-0.5) -> " + to_string(trunc(-0.5))) // 0
|
||||
|
||||
print("=== math trunc demo end ===")
|
||||
|
||||
/* Expected output (values):
|
||||
=== math trunc demo start ===
|
||||
trunc(3.7) -> 3
|
||||
trunc(3.0) -> 3
|
||||
trunc(-3.7) -> -3
|
||||
trunc(-3.0) -> -3
|
||||
trunc(0.5) -> 0
|
||||
trunc(-0.5) -> 0
|
||||
=== math trunc demo end ===
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue