Julia: leading_zeros(::BigInt) not defined

Created on 5 Apr 2019  Â·  4Comments  Â·  Source: JuliaLang/julia

Julia 1.1.0

julia> leading_zeros(BigInt(1))
ERROR: MethodError: no method matching leading_zeros(::BigInt)

trailing_zeros(::BigInt) is defined so I think it makes sense that leading_zeros(::BigInt) is also defined.

Most helpful comment

But what is the correct answer to leading_zeros(BigInt(1))?

All 4 comments

But what is the correct answer to leading_zeros(BigInt(1))?

It should return 63.
i.e. for BigInt x: leading_zeros(unsafe_load(x.d, abs(x.size)))
But I am not sure what should be the behavior for -ve BigInts.

I think that's questionable; it feels like leaking an implementation detail (the size of limbs used to represent BigInts).

Agree. I had not considered that before. Shall I close this issue then?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

omus picture omus  Â·  3Comments

felixrehren picture felixrehren  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments