Skip to content

Commit

Permalink
Add Emscripten globals for Infinity and NaN to fix printf for these v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
bjfish committed Dec 16, 2018
1 parent ae21025 commit de85ab9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
26 changes: 13 additions & 13 deletions emtests/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions emtests/printf.output
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified emtests/printf.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions src/apis/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _));
Expand Down

0 comments on commit de85ab9

Please sign in to comment.