I want to both compute m and check that it is an integer.
If log(b,y) was exact it would return exactly m when y = b^m so I would just do m = Int(log(b,y)).
However, it seems that in some case this do not work e.g. m = Int(log(b,7,7^5)).
Thus, the floating point log breaks the representability of the result as an Integer.
The function should probably be something on the lines of:
julia> function logi(x::Int,y::Int)
x == 0 && error()
i = 0
r = x
while abs(r) < abs(y)
i += 1
r *= x
r == y ? i+1 : error()
logi (generic function with 2 methods)
but written more carefully, because that one fails in a series of cases, for instance:
julia> function logi(b::Int, y::Int)
n = round(Int, log(b, y))
b^n == y || throw(ArgumentError("$y is not a power of $b"))
logi (generic function with 1 method)
julia> using BenchmarkTools
julia> b = 5; y = 5^12;
julia> @btime logi($b, $y)
32.060 ns (0 allocations: 0 bytes)
Yeah. It’s only hard with a modulo. Without, there is a simple algorithm that’s O(log(n)) steps that just repeatedly squares until you pass the number and than does a binary search to find the true answer.