Expand description
The float functions of the Microsoft C runtime, as the game calls them: sinf, cosf,
acosf and atan2f.
These functions are not correctly rounded, so their results can differ from Rust’s f32::sin
and its relatives in the last bit. That is enough to change the game’s results. So this module
ports the C runtime’s own algorithms, operation by operation, and simulation code uses them.
tools/emu/crt_math.py checks them against the original functions. powf, floorf and
sqrtf are correctly rounded in both, so Rust’s own functions give the same results.
use banished_core::crt;
let s = crt::sinf(0.5);
let angle = crt::atan2f(1.0, 2.0);
assert!(s > 0.47 && angle > 0.46);Original: FUN_140137160 (sinf, the Runtime’s copy at 0x18012a620 is the same),
FUN_140136560 (cosf, Runtime 0x1801295a0), FUN_140136090 (acosf), Runtime
0x180128f10 (atan2f, behind Vector3::Heading).
Functions§
- acosf
- The arc cosine of
x, in radians, as the C runtime’sacosfcomputes it. - atan2f
- The angle of the point
(x, y), in radians from -π to π, as the C runtime’satan2fcomputes it. - cosf
- The cosine of
x(radians), as the C runtime’scosfcomputes it. - sinf
- The sine of
x(radians), as the C runtime’ssinfcomputes it.