Add Emscripten globals for Infinity and NaN to fix printf for these values

This commit is contained in:
Brandon Fish 2018-12-16 13:50:54 -06:00
parent ae210253b6
commit de85ab943a
4 changed files with 35 additions and 13 deletions

View File

@ -28,18 +28,18 @@ int main() {
printf("%s %%\n", "A string"); printf("%s %%\n", "A string");
printf("Null string: %7s\n", NULL); printf("Null string: %7s\n", NULL);
// printf("Null pointer: %p\n", NULL); // printf("Null pointer: %p\n", NULL);
// printf("%lf\n", INFINITY); printf("%lf\n", INFINITY);
// printf("%lF\n", INFINITY); printf("%lF\n", INFINITY);
// printf("%lf\n", -INFINITY); printf("%lf\n", -INFINITY);
// printf("%lF\n", -INFINITY); printf("%lF\n", -INFINITY);
// printf("%lf\n", NAN); printf("%lf\n", NAN);
// printf("%lF\n", NAN); printf("%lF\n", NAN);
// printf("%10f\n", NAN); printf("%10f\n", NAN);
// printf("%-10f\n", NAN); printf("%-10f\n", NAN);
// printf("%010.2f\n", NAN); printf("%010.2f\n", NAN);
// printf("%-010.2f\n", NAN); printf("%-010.2f\n", NAN);
// printf("%10.f\n", INFINITY); printf("%10.f\n", INFINITY);
// printf("%-10.f\n", -INFINITY); printf("%-10.f\n", -INFINITY);
// printf("--rest--\n"); // printf("--rest--\n");
// printf("in%%3.5valid\n", 0); // printf("in%%3.5valid\n", 0);
// printf("%.f\n", 0.0f); // printf("%.f\n", 0.0f);

View File

@ -15,3 +15,15 @@ Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10 Width trick: 10
A string % A string %
Null string: (null) Null string: (null)
inf
INF
-inf
-INF
nan
NAN
nan
nan
nan
nan
inf
-inf

Binary file not shown.

View File

@ -91,6 +91,16 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
"DYNAMICTOP_PTR", "DYNAMICTOP_PTR",
ImportValue::Global(dynamictop_ptr(STATIC_BUMP) as _), ImportValue::Global(dynamictop_ptr(STATIC_BUMP) as _),
); );
import_object.set(
"global",
"Infinity",
ImportValue::Global(std::f64::INFINITY.to_bits() as _),
);
import_object.set(
"global",
"NaN",
ImportValue::Global(std::f64::NAN.to_bits() as _),
);
import_object.set("env", "tableBase", ImportValue::Global(0)); import_object.set("env", "tableBase", ImportValue::Global(0));
// Print functions // Print functions
import_object.set("env", "printf", ImportValue::Func(io::printf as _)); import_object.set("env", "printf", ImportValue::Func(io::printf as _));