| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Need sqrt() algorithm |
Quoting (part of) a msg from you of 08 Nov 1994: RB> I need to do a distance calculation between two points RB> (x0,z0) and (x1,z1). The way I know to do this is to use RB> the distance formula, but it requires a square root RB> calculation. I don't want to use the standard C sqrt() RB> function because I am not using floating point for anything RB> else. Rob, If you are going to use the mentioned Newton Raphson method (and why not), then it helps if the first appromimation is as close as possible with a simple calculation. Since you basically need the hypothenuse of a right-angled triangle, you know the limits of the result. If we call the sides 'a' and 'b' and the hypothenuse 'c' then: - c greater than max(a,b) - c shorter than sqrt(2) * (a+b)/2 . . . (maximum if a==b) So a good approximation-formula seems to be: (a+b) * 3 / 5 And as reaction to the arguments about floating-point support being 'standard' in OS/2, I would say: If the co-ordinates and the result have to be integer-values, you need 3 type conversions for every calculation. This might be more resource consuming than the integer approximation itself! You would have to write a small 'benchmark'-program to verify this. Cheers, Rob --- timEd/2 1.01+* Origin: PC-SquareRoot of Downsort (2:280/804.1098) SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413 SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1 @PATH: 1004/1098 280/804 801 24/24 396/1 3615/50 229/2 12/2442 @PATH: 711/409 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.