floating point - Precision in Erlang -


next code gives me 5.999999999999998 in result, right answer 6.

alpha = math:acos((4*4 + 5*5 - 3*3) / (2*4*5)) area = 1/2 * 4 * 5 * math:sin(alpha) 

is possible 6?

you have run problem common has own web site, what every programmer should know floating-point arithmetic. problem due way floating-point arithmetic works in pretty every cpu on market supports fp arithmetic; not specific erlang.

if regular floating point arithmetic not give precision or accuracy need, can use arbitrary precision arithmetic library instead of built-in arithmetic. perhaps well-known such library gmp, you'd have wrap in nifs use erlang.

there at least 1 pure-erlang alternative, have no experience it, cannot endorse it.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -