3 ms·
I was surprised to see that your version of 0 ran nearly as fast as the others, despite the multiple calls to the square root. Then I realised that you're usin
by ColinWright 8y ago
I was surprised to see that your version of 0 ran nearly as fast as the others, despite the multiple calls to the square root. Then I realised that you're using the library sqrt routine, and I wonder if that would be accurate enough for the case I'm usually in where my numbers have hundreds of digits. I don't know what algorithm Julia uses for that, but I've found floats (and their friends) insufficiently accurate.
But that's useful feedback - thank you.
- yoklov 8y agoI haven't used Julia in quite a while, but given its focus on numerical computation it would be fairly surprising to me if it didn't have the ability to meet your precision needs.
- kristofferc 8y agoIf you need higher precision you could always either simply bump up the accuracy a bit using e.g. https://github.com/JuliaMath/DoubleDouble.jl https://github.com/JuliaMath/DoubleDouble.jl or you can use the arbitrary precision numbers in Julia (https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/index.html#Arbitrary-Precision-Arithmetic-1 https://docs.julialang.org/en/v1/manual/integers-and-floatin...) The performance will of course change accordingly.
- ColinWright 8y agoIs there an arbitrary precision square root routine? I've not found it ...
- kristofferc 8y agoThe concrete routine that is dispatched to is based on the type of the input number. So `sqrt(2.0)` will, in the end, call the assembly-instruction (depending on your specific CPU) `vsqrtss` since the input type is a 64-bit float, `sqrt(Float32(2.0))` will end up calling `vsqrtsd`, `sqrt(big"2.0")` will call the sqrt from the arbitrary precision library (MPFR) since we now have a "BigFloat" number etc. Directly from a Julia REPL session: julia> sqrt(2.0) 1.4142135623730951 julia> sqrt(Float32(2.0)) 1.4142135f0 julia> sqrt(big"2.0") 1.414213562373095048801688724209698078569671875376948073176679737990732478462102 julia> setprecision(512) # Bump the precision 512 julia> sqrt(big"2.0") 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993586
- ColinWright 8y agoYes, but I'm talking about getting exact BigInt ceil square roots of BigInt inputs. I've not found anything about whether that is supported natively or in a library.