| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pythagorean Triples |
-> Errr ... perhaps I meant `long integers'. Nevertheless, the
-> programme is impressively fast - and superbly annotated....
The DEFLNG A-Z at the beginning makes the variables default to "long"
(32-bit) integers, unless their names carry suffixes such as "$"
or "#"
to indicate some other type. In fact, there is only one variable that
isn't a long integer, Z#, which is shorthand for SQR(2) + 1.
I did produce a version, a week or so ago, in which I used DEFDBL
instead of DEFLNG, and changed all the integer operations to
floating-point ones. It could handle values of A up to 2^27 (more than
130 *million*), and the values of B and C were sometimes 16 decimal
digits long! It was fun in a way, but catastrophically slow.
Floating-point arithmetic is *far* slower than integer arithmetic. I
stashed it away on my disk, and didn't take it any further. The integer
version does everything I can imagine anyone wanting it to do, and much
more neatly and quickly.
Here's an example of how clumsy it got. The upper loop-limit for the
FOR D... loop in the Odd case can be calculated to be the next-lower
*odd* integer to SQR(S/Z#), where S is A/2. In integer arithmetic, I
can write it as:
J = INT(SQR(S / Z#)) - 1 OR 1
In floating-point arithmetic, I had to do something like:
T# = SQR(S / Z#)
U = 2 * INT(T# / 2)
IF T# - U > 1 THEN J = U + 1 ELSE J = U - 1
Three lines to replace one!
dow
--- Platinum Xpress/Win/WINServer v3.0pr5
* Origin: The Bayman BBS,Toronto, (416)698-6573 - 1:250/514 (1:250/514)SEEN-BY: 633/267 270 @PATH: 250/514 123/500 106/2000 633/267 |
|
| 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™.