Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f32 toString emits extra decimals #2873

Open
mattjohnsonpint opened this issue Sep 26, 2024 · 1 comment
Open

f32 toString emits extra decimals #2873

mattjohnsonpint opened this issue Sep 26, 2024 · 1 comment
Labels

Comments

@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Sep 26, 2024

Bug description

Calling toString on an f64 value works as expected, but doing the same on an f32 string introduces extra noise decimals. I suspect it is because the f32 value is being cast to f64 when passed into the dtoa function:

toString(this: f32, radix: i32 = 0): String {
return dtoa(this);
}

export function dtoa(value: f64): String {

Steps to reproduce

console.log((<f64>1.1).toString());  // "1.1"
console.log((<f32>1.1).toString());  // "1.100000023841858"

AssemblyScript version

v0.27.29

@mattjohnsonpint
Copy link
Contributor Author

Perhaps not the cast itself, but rather dtoa is designed for 64-bit precision input value. If there were a 32-bit version of dtoa and its dependent functions, then it should be possible to emit "1.1" for an f32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant