[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Comment about IEEE floating-point rounding... (was: Setting Float Precision in Lua.c)**
**From**: Albert Chan <albertmcchan@...>
**Date**: Tue, 12 Jun 2018 15:08:11 -0400

> By the way, the link to Prof. Kahan's article on miscalculating the
> areas and angles of triangles has moved. It can now be found at:
>
> http://http.cs.berkeley.edu/~wkahan/Triangle.pdf
>
> -- Hugo
Thanks. I just think of another way to reduce error,
for calculating the area of the needle-like triangle.
I use another IEEE double property.
If value is integer 53 bits or less, add, subtract, multiply is *exact*
Sorry if it sound obvious to everyone, it is stated in PIL on Numbers
Example, Above article, Table 1 (line 3) sides of triangle:
a, b, c = 1e5, 99999.99979, 0.00029
This is the classic Heron formula for triangle area:
Area = sqrt(s * (s-a) * (s-b) * (s-c)), where s = (a + b + c) / 2
Instead of plugging in the numbers, just scaled it so all values
are integers. Scale by 1e5: a,b,c = 1e10, 9999999979, 29
Area (scaled) = sqrt(10000000004 * 4 * 25 * 9999999975)
= 99999999895
Undo scaling: Area = 99999999895 / 1e10 = 9.9999999895
BTW, the article stated that heron formula return area = 17.6
I cannot reproduce it (even adjusting precision with gmpy2)
Anyone still have the old HP-15C calculator ?