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/c/simple_crt.c | |
| 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/c/simple_crt.c')
| -rw-r--r-- | src/main/c/simple_crt.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/c/simple_crt.c b/src/main/c/simple_crt.c index 438ae5f9..e50042c2 100644 --- a/src/main/c/simple_crt.c +++ b/src/main/c/simple_crt.c @@ -3,9 +3,32 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <math.h> #include <termios.h> #include <unistd.h> +// Fixed-semantics compiler intrinsics. Keep these definitions for indirect +// calls; direct calls may inline to representation-preserving register moves. +int64_t simple_f64_bits(double value) { + int64_t bits; + memcpy(&bits, &value, sizeof(bits)); + return bits; +} +double simple_f64_from_bits(int64_t bits) { + double value; + memcpy(&value, &bits, sizeof(value)); + return value; +} + +// Floating remainder's machine instruction uses this memory-preserving helper. +double simple_f64_mod(double x, double y) { + // fmod can set errno for NaN-producing inputs; arithmetic leaves it alone. + int saved_errno = errno; + double result = fmod(x, y); + errno = saved_errno; + return result; +} + // errno may be thread-local or a macro calling a platform accessor. int32_t simple_errno(void) { return errno; } int32_t simple_set_errno(int32_t error) { errno = error; return -1; } |
