diff --git a/emtests/printf.c b/emtests/printf.c index 55abc0ad5..603ad5feb 100644 --- a/emtests/printf.c +++ b/emtests/printf.c @@ -27,19 +27,19 @@ int main() { printf("Width trick: %*d\n", 5, 10); printf("%s %%\n", "A string"); printf("Null string: %7s\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", NAN); -// printf("%lF\n", NAN); -// printf("%10f\n", NAN); -// printf("%-10f\n", NAN); -// printf("%010.2f\n", NAN); -// printf("%-010.2f\n", NAN); -// printf("%10.f\n", INFINITY); -// printf("%-10.f\n", -INFINITY); +// 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", NAN); + printf("%lF\n", NAN); + printf("%10f\n", NAN); + printf("%-10f\n", NAN); + printf("%010.2f\n", NAN); + printf("%-010.2f\n", NAN); + printf("%10.f\n", INFINITY); + printf("%-10.f\n", -INFINITY); // printf("--rest--\n"); // printf("in%%3.5valid\n", 0); // printf("%.f\n", 0.0f); diff --git a/emtests/printf.output b/emtests/printf.output index 5136a9d2b..ac02f590a 100644 --- a/emtests/printf.output +++ b/emtests/printf.output @@ -15,3 +15,15 @@ Force sign or space: 3.14 -3.14 3.14 -3.14 Width trick: 10 A string % Null string: (null) +inf +INF +-inf +-INF +nan +NAN + nan +nan + nan +nan + inf +-inf diff --git a/emtests/printf.wasm b/emtests/printf.wasm index bd5c1ebf4..69cc16f2b 100644 Binary files a/emtests/printf.wasm and b/emtests/printf.wasm differ diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index 601a631ae..f1520c9d9 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -91,6 +91,16 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "DYNAMICTOP_PTR", 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)); // Print functions import_object.set("env", "printf", ImportValue::Func(io::printf as _));