[erlang-questions] bignum sqrt broken in erlang?

Richard O'Keefe ok@REDACTED
Wed Aug 26 00:15:45 CEST 2009


On Aug 26, 2009, at 1:11 AM, Angel Alvarez wrote:
> 2> R0=trunc(math:sqrt(N)).
> 267659337146589062070609641472

Right there is your problem.
math:sqrt/1 is a FLOATING-POINT square root.
The argument is first rounded to floating point,
then its square root taken, and then you truncate that.

As far as I know, Erlang doesn't have a built-in
integer square root function, but it's straightforward
enough to write one.



More information about the erlang-questions mailing list