Skip to content

Floating Point

Yuki Kimoto edited this page Apr 29, 2024 · 3 revisions

Why SPVM floating point literal is differenct from C floatin point literal in 32bit CPU

SPVM uses C functions strtof and strtod to produce a floating point from SPVM floating point literal.

But the functions to produce a floating point can be different in strtof(or strtod) and C floating point literal.

See the following article about the reason. This is Windows document, but the reason is the same as on Linux.

https://learn.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=msvc-170

Why is the strinfication of infinity and NaN different on Windows and Linux?

# inf, 1.#INF, etc
my $inf = 1.0 / 0.0;
warn $inf;

# nan, -nan, 1.#IND, etc
my $nan = 0.0 / 0.0;
warn $nan;

See the following topic for the reason.

https://learn.microsoft.com/en-us/cpp/porting/visual-cpp-change-history-2003-2015?view=msvc-170#stdio_and_conio

Because the floating-point output problem is complex, SPVM chose not to solve it.

Clone this wiki locally