Hacker News new | past | comments | ask | show | jobs | submit login

Is round(x) broken?

    Julia's standard library includes a host of mathematical functions, in addition to the standard operators. Complex numbers are also supported, using the built-in im unit:

    round(pi) 
    lcm(54, 392, 232) # least common multiple 
    sqrt(square(100)) 
    e^(pi * im) 
    log(e ^ 2) + log10(100)

    When you're ready, type "next" to continue
    julia> round(pi)
    no method round(MathConst{:π},)



To give some context, several common math constants are use the MathConst type to provide multi-precision constants. This allows e.g. a*pi to be extremely accurate if a is, e.g. a BigInt.

This issue was also reported at https://github.com/JuliaLang/julia/issues/5561


round(x) only works for a few specialised types of x. help(round) tells you that it will return the same type then. Of course for a type of MathConst{:π}, that won’t work. For generic types, you need to at least specify the number of digits (round(pi, 3)). (See also: methods(round))


Weird that they have round(pi) as an example.


It may have worked at some point. The language evolves pretty quickly at the moment.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: