gcd() ... wrong answer, lcm() hangs

May 20, 2008
11,400
99
Syracuse, NY, USA
This is correct.
Code:
v:\> echo %@eval[gcd(2546068882500000000 99999900000000000)]
357142500000000

If I multiply both numbers by 10, their GCD should be multiplied by 10. But this is not correct.
Code:
v:\> echo %@eval[gcd(25460688825000000000 999999000000000000)]
3584

And this puts TCC in an uninterruptible, 100% CPU usage state.
Code:
v:\> echo %@eval[lcm(25460688825000000000 999999000000000000)]
 
May 20, 2008
11,400
99
Syracuse, NY, USA
And here's a peculiar one. The correct answer is 10**18, but I get 2**18.
Code:
v:\> echo %@eval[gcd(%@eval[10**18] %@eval[10**19])]
262144
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Note that @EVAL was necessary in my last example. The arguments to gcd() are not expanded, and, as mentioned in another thread, variable names without a leading '%' are not expanded.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
WAD - you're overflowing the 64-bit integer arguments & result. I've added an overflow check to lcm in build 47 to prevent it from looping.

Those operators could (with substantial effort) be rewritten to use BCD instead, but I doubt you actually need it.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
WAD - you're overflowing the 64-bit integer arguments & result. I've added an overflow check to lcm in build 47 to prevent it from looping.

Those operators could (with substantial effort) be rewritten to use BCD instead, but I doubt you actually need it.
Actually, I needed it. How do you think I discovered it?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
LCM's overflow check apparently works. GCD can also hang TCC and would seem to need a similar check. THis will do it.
Code:
echo %@eval[gcd(1111111111118077966350999 1111111111118077966350888)]
 
Similar threads
Thread starter Title Forum Replies Date
vefatica gcd() and lcm() ... need '%' Support 10
JohnQSmith New online help file wrong logo Support 7
vefatica @EXECSTR ... TCSTART ... something's wrong! Support 7
R History window wrong size, can't remember size change Support 12
mfarah Fixed The DATE command produces the wrong error message. Support 1
MikeBaas @regsetenv complains "wrong parameter" Support 14
mikea How to? TCC registered to wrong 'entity' Support 5
T @replace -- what is wrong here Support 2
vefatica Fixed KEYSTACK /i with repeat count sends wrong keys Support 7
C ZIP/U compares wrong timestamp Support 13
vefatica @WORDS, often wrong Support 0
D What is wrong with this code? Support 7
vefatica WAD DIR /HL still gets names wrong Support 16
H Fixed DIR /G returns wrong sizes Support 2
M Another "What is wrong?" Support 8
M What is wrong with this command? Support 4
vefatica Updater says wrong version Support 1
CWBillow Wrong icons keep sticking Support 6
M How to? What am I doing wrong/not understanding? Support 10
C News link wrong Support 1
M What am I doing wrong? Support 12
M What am I doing wrong here? Support 2
C Forum column headings wrong? Support 4
gschizas Installation folder for TCMD x64 15.1 is wrong Support 5
Dan Glynhampton Documentation v15 help: ECHOXERR Help Page Title is Wrong Support 0
M What am I doing wrong in this (very simple!) code? Support 3
vefatica Something wrong with @PID Support 10
J zip wrong central directory signature Support 12
S Fixed _DO_FILES and _DO_DIRS wrong Support 0
B Downloading Updates - Error: Wrong file size?? Support 3
vefatica What's wrong here? Support 2
vefatica Wrong startup file? Support 1
M How to? Missing closing quote: What am I doing wrong???? Support 7
gschizas (minor) Help topic "Colors, Color Names and Codes" is wrong Support 0
T Wrong prompt in Windows command console Support 3
M Where am I going wrong with ALIAS??? Support 7
G Wrong File Size Support 8
vefatica Updating v10: error wrong file size Support 2
S Wrong .INI file used by TCC Support 2
K_Meinhard Wrong sender adress Support 0
T input accepts empty answer Support 5

Similar threads