Floor? Force magnitude amount?

Hey all,

Newer to julia and working with some very large numbers. Unfort conditioning of the system im using leads to numerical issues with numbers spanning more than 12 orders of magnitude.

I’ve been working in bigInt and trying things like Float64(quantity*1e-10, RoundDown)
But my numbers can go anywhere from 1e24, 1e12 1e7, 1ewhatever anything really and majority over 12. So theres gotta be a way to just force numbers to be no more than 1e12 or 1e#, like a floor or round im not to sure the best way.

Really grateful for you julia pros! Cheers! :slight_smile:

How about min(x, 1e12)?

1 Like

I’m unclear on the specification but for some interpretation, exp10(floor(log10(x))) might be an option.

1 Like

I’m not sure about the specification either, but in case you want the values to be limited to a maximum value, clamp is worth a look.

julia> clamp.([1e24, 1e13, 1e12, 1e7], floatmin(), 1e12)
4-element Vector{Float64}:

A single-sided clamp is just a min or a max. In this case min.([1e24, 1e13, 1e12, 1e7], 1e12) gives the same result.


thanks so much guys :smiley: