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

[BUG] Invalid stochastic rounding with infinite #48

Closed
Thukisdo opened this issue Jul 28, 2021 · 5 comments
Closed

[BUG] Invalid stochastic rounding with infinite #48

Thukisdo opened this issue Jul 28, 2021 · 5 comments
Assignees

Comments

@Thukisdo
Copy link

Hi,

We've spotted an issue in Float32_stochastic_round() where rounding an Infinite will sometime return NaN, where we may expect Infinite, see output below.

julia> Float32(Float32_stochastic_round(Inf))
Inf32

julia> Float32(Float32_stochastic_round(Inf))
NaN32

The only difference between NaN and infinite is an empty mantissa, hence adding a random noise will result in NaN.

@milankl
Copy link
Owner

milankl commented Sep 7, 2021

Sorry @Thukisdo, missed that issue. Yes, I observed that earlier, but couldn't be bothered resolve this, as I didn't think this would be of practical importance. But maybe that's also me thinking that NaR (= one bitpattern for NaN, +-Inf) from posits is a good idea. I guess this could be resolved by another early exit, something like isfinite(x) || return BFloat16sr(x) such that for x=NaN32 it returns NaNB16sr and for x=Inf32 it returns Inf16sr ?

@milankl milankl self-assigned this Sep 7, 2021
@Thukisdo
Copy link
Author

Thukisdo commented Sep 8, 2021

No problem :)

Indeed, i also solved it using an early exit in my code.

@milankl
Copy link
Owner

milankl commented Sep 8, 2021

Happy for you to create a PR with your solution?

@Thukisdo
Copy link
Author

Thukisdo commented Sep 8, 2021

I applied this fix in a C++ adaptation of your rounding method here, so i unfortunately do not have a patched Julia version.

@milankl
Copy link
Owner

milankl commented Oct 12, 2021

Thanks @Thukisdo, this is addressed in upcoming v0.6.1 as I've replaced the stochastic rounding via signed integer arithmetic with unsigned integers. This avoids any stochastic rounding between Inf and NaN and doesn't require a check for special cases like isfinite(x) || return ... or isnan(x) || return .... Check the new Float32_stochastic_rounding function definition if you are interested!

@milankl milankl closed this as completed Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants