How to get the significand and the exponent of a floating point number?

Given a floating point number, I would like to print the significand and the exponent in binary. This is for teaching purposes.

I guess I can use mathematical functions to get them but on one hand it seems that this cannot be the easiest way and on the other hand it may introduce some error.

Is there any build in way to do that?

1 Like

Use exponent and significand to get exponent and mantissa of a float. There is also bitstring which will return the binary representation as a string.

5 Likes

Oh, that was quite obvious I guess :neutral_face:

Thanks!

In these cases the function apropos is quite useful:

julia> apropos("significand")
Base.isapprox
Base.Math.significand
Base.Math.fromfraction

julia> apropos("exponent")
Base.:^
Base.retry
Base.ExponentialBackOff
Base.Math._frexp_exp
Base.exp
Base.Math._approx_cbrt
Base.Math._ldexp_exp
Base.exp2
Base.Math.exponent
Base.exp10
Random.DSFMT.MEXP
Random.DSFMT.calc_jump
Random.DSFMT.Poly19937
Random.DSFMT.JPOLY1e20
Random.randexp!
Random.randexp
Base.exp
Base.:^
Distributed.pmap

:wink:

3 Likes