Order of magnitude of a float in Julia 1.6

Viewed 118

Is there a way to determine the order of magnitude of a float in Julia 1.6?

For instance, a function such that OrderOfMagnitude(1000) = 3.

1 Answers

There are various definitions of order of magnitude, some of them are (assuming x is positive):

  • floor(Int, log10(x))
  • floor(Int, log10(2*x))
  • floor(Int, log10(sqrt(10)*x))
Related