Fix printing float results from the CLI (#2797)

Previously their bit patterns were printed interpreted as decimals, now
they're printed as floats.
This commit is contained in:
Alex Crichton
2021-04-02 10:07:59 -05:00
committed by GitHub
parent 90aa5cf49f
commit 29949505d6
3 changed files with 26 additions and 4 deletions

View File

@@ -333,10 +333,10 @@ impl RunCommand {
match result { match result {
Val::I32(i) => println!("{}", i), Val::I32(i) => println!("{}", i),
Val::I64(i) => println!("{}", i), Val::I64(i) => println!("{}", i),
Val::F32(f) => println!("{}", f), Val::F32(f) => println!("{}", f32::from_bits(f)),
Val::F64(f) => println!("{}", f), Val::F64(f) => println!("{}", f64::from_bits(f)),
Val::ExternRef(_) => println!("<externref>"), Val::ExternRef(_) => println!("<externref>"),
Val::FuncRef(_) => println!("<externref>"), Val::FuncRef(_) => println!("<funcref>"),
Val::V128(i) => println!("{}", i), Val::V128(i) => println!("{}", i),
} }
} }

View File

@@ -97,6 +97,26 @@ fn run_wasmtime_simple_wat() -> Result<()> {
"--disable-cache", "--disable-cache",
"4", "4",
])?; ])?;
assert_eq!(
run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--invoke",
"get_f32",
"--disable-cache",
])?,
"100\n"
);
assert_eq!(
run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--invoke",
"get_f64",
"--disable-cache",
])?,
"100\n"
);
Ok(()) Ok(())
} }

View File

@@ -2,4 +2,6 @@
(func (export "simple") (param i32) (result i32) (func (export "simple") (param i32) (result i32)
local.get 0 local.get 0
) )
(func (export "get_f32") (result f32) f32.const 100)
(func (export "get_f64") (result f64) f64.const 100)
) )