diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-15 11:20:40 -0800 |
| commit | 658289861e8d971cd9e449e66a749c9c2d65f623 (patch) | |
| tree | 209a32ef7fab1d27222121bc8b53a968ff4b6796 /src/main/smp/sys/math.smp | |
| parent | 77ae05305a5653a2353709564705819f201e587f (diff) | |
| download | Simple-658289861e8d971cd9e449e66a749c9c2d65f623.tar.gz Simple-658289861e8d971cd9e449e66a749c9c2d65f623.zip | |
Chapter 31: Software Drawing, Time, and Graphical Gameslinear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/main/smp/sys/math.smp')
| -rw-r--r-- | src/main/smp/sys/math.smp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/smp/sys/math.smp b/src/main/smp/sys/math.smp new file mode 100644 index 00000000..33bb0e5f --- /dev/null +++ b/src/main/smp/sys/math.smp @@ -0,0 +1,27 @@ +// Mathematical constants, rounded to the nearest f64 value. +val PI = 3.141592653589793; +val E = 2.718281828459045; + +// Native libm functions, all f64 -> f64. sin/cos take radians; exp is e^x, +// log is the natural logarithm, and sqrt is the nonnegative square root. +// These are ordinary C calls: results and domain/range errors (including +// errno) follow the host libm. They are not folded or treated as pure intrinsics. +// The standard linker already includes -lm. +{ f64 -> f64 } sin = "C"; +{ f64 -> f64 } cos = "C"; +{ f64 -> f64 } exp = "C"; +{ f64 -> f64 } log = "C"; +{ f64 -> f64 } sqrt = "C"; + +// Fixed-semantics C bindings recognized by the compiler's intrinsic inliner. +// See chapter31/README.md, "Math support and intrinsics", for the compiler contract. +// These preserve all 64 bits, including signed zero and NaN payloads. +// They are NOT numeric conversions (ordinary typed assignments still are). +{ f64 -> i64 } simple_f64_bits = "C"; +{ i64 -> f64 } simple_f64_from_bits = "C"; +val f64Bits = simple_f64_bits; +val f64FromBits = simple_f64_from_bits; + + +val max = { f64 x, f64 y -> return x > y ? x : y; }; +val min = { f64 x, f64 y -> return x < y ? x : y; }; |
