More math opcode Fun. (0.37.43)
This commit is contained in:
parent
194c06e4aa
commit
c062b685e1
18 changed files with 501 additions and 2 deletions
30
examples/math_cos.fun
Normal file
30
examples/math_cos.fun
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/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 cos(x)
|
||||
|
||||
print("=== math cos demo start ===")
|
||||
|
||||
print("cos(0) -> " + to_string(cos(0)))
|
||||
print("cos(3.14159265359) ~ pi -> " + to_string(cos(3.14159265359)))
|
||||
print("cos(1.57079632679) ~ pi/2 -> " + to_string(cos(1.57079632679)))
|
||||
|
||||
print("=== math cos demo end ===")
|
||||
|
||||
/* Expected output (approximate):
|
||||
=== math cos demo start ===
|
||||
cos(0) -> 1
|
||||
cos(3.14159265359) ~ pi -> -1
|
||||
cos(1.57079632679) ~ pi/2 -> 0
|
||||
=== math cos demo end ===
|
||||
*/
|
||||
34
examples/math_exp_log.fun
Normal file
34
examples/math_exp_log.fun
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/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 exp(x), log(x), log10(x)
|
||||
|
||||
print("=== math exp/log demo start ===")
|
||||
|
||||
print("exp(0) -> " + to_string(exp(0)))
|
||||
print("log(1) -> " + to_string(log(1)))
|
||||
print("log10(1) -> " + to_string(log10(1)))
|
||||
print("exp(1) -> " + to_string(exp(1)))
|
||||
print("log(2.71828182846) ~ ln(e) -> " + to_string(log(2.71828182846)))
|
||||
|
||||
print("=== math exp/log demo end ===")
|
||||
|
||||
/* Expected output (approximate):
|
||||
=== math exp/log demo start ===
|
||||
exp(0) -> 1
|
||||
log(1) -> 0
|
||||
log10(1) -> 0
|
||||
exp(1) -> 2.718281828...
|
||||
log(2.71828182846) ~ ln(e) -> 1
|
||||
=== math exp/log demo end ===
|
||||
*/
|
||||
30
examples/math_sin.fun
Normal file
30
examples/math_sin.fun
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/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 sin(x)
|
||||
|
||||
print("=== math sin demo start ===")
|
||||
|
||||
print("sin(0) -> " + to_string(sin(0)))
|
||||
print("sin(1.57079632679) ~ pi/2 -> " + to_string(sin(1.57079632679)))
|
||||
print("sin(-1.57079632679) -> " + to_string(sin(-1.57079632679)))
|
||||
|
||||
print("=== math sin demo end ===")
|
||||
|
||||
/* Expected output (approximate):
|
||||
=== math sin demo start ===
|
||||
sin(0) -> 0
|
||||
sin(1.57079632679) ~ pi/2 -> 1
|
||||
sin(-1.57079632679) -> -1
|
||||
=== math sin demo end ===
|
||||
*/
|
||||
32
examples/math_sqrt.fun
Normal file
32
examples/math_sqrt.fun
Normal 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 sqrt(x)
|
||||
|
||||
print("=== math sqrt demo start ===")
|
||||
|
||||
print("sqrt(0) -> " + to_string(sqrt(0)))
|
||||
print("sqrt(9) -> " + to_string(sqrt(9)))
|
||||
print("sqrt(2) -> " + to_string(sqrt(2)))
|
||||
print("sqrt(-1) -> " + to_string(sqrt(-1))) // NaN expected
|
||||
|
||||
print("=== math sqrt demo end ===")
|
||||
|
||||
/* Expected output (approximate):
|
||||
=== math sqrt demo start ===
|
||||
sqrt(0) -> 0
|
||||
sqrt(9) -> 3
|
||||
sqrt(2) -> 1.41421356...
|
||||
sqrt(-1) -> nan
|
||||
=== math sqrt demo end ===
|
||||
*/
|
||||
28
examples/math_tan.fun
Normal file
28
examples/math_tan.fun
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/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 tan(x)
|
||||
|
||||
print("=== math tan demo start ===")
|
||||
|
||||
print("tan(0) -> " + to_string(tan(0)))
|
||||
print("tan(0.78539816339) ~ pi/4 -> " + to_string(tan(0.78539816339)))
|
||||
|
||||
print("=== math tan demo end ===")
|
||||
|
||||
/* Expected output (approximate):
|
||||
=== math tan demo start ===
|
||||
tan(0) -> 0
|
||||
tan(0.78539816339) ~ pi/4 -> 1
|
||||
=== math tan demo end ===
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue