Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001021Core InformEquations, units, arithmeticpublic2012-10-06 15:042014-05-07 07:34
Reporterclimbingstars 
Assigned Tograham 
PrioritynormalSeverityseriousReproducibilityalways
StatusclosedResolutionfixed 
Platformx86OSWindowsOS VersionXP
Product Version6G60 
Target VersionFixed in Version6L02 
Summary0001021: Calculating the square root returns minus one for certain values
DescriptionInform fails to calculate the square root of numbers 16384-32767 for zcode and 1073741824-2147483647 for glulx returning minus one instead.
Minimal Source Text To Reproduce
"Test"

Numbering is an action applying to one number. Understand "[number]" as numbering.

Report numbering (this is the standard report numbering rule):
say "[number understood] => [square root of number understood][line break]".

The Testing Room is A Room.

Test zcode with "16383 / 16384 / 32767 / 32768".

Test glulx with "1073741823 / 1073741824 / 2147483647 / 2147483648".
Additional InformationThis works as an alternative.

Include (-

[ SquareRoot num op res one pole;
pole = 0;
op = num;
if (num < 0) { RunTimeProblem(RTP_NEGATIVEROOT); return 1; }
! "one" starts at the highest power of four <= the argument.
for (one = WORD_NEXTTOHIGHBIT: one > op: one = one/4) ;
while (one ~= 0) {
!print "Round: op = ", op, " | res = ", res, " | res**2 = ", res*res, " | one = ", one, "^";
if (op >= res + one) {
op = op - res - one;
if (one < 16384) {
res = res + one*2;
}
else {
pole = 1;
res = res/2;
res = res + one;
}
}
if (pole == 0) {
res = res/2;
}
else {
pole = 0;
}
one = one/4;
}
!print "Round: op = ", op, " | res = ", res, " | res**2 = ", res*res, " | one = ", one, "^";
!print "Res is ", res, "^";
return res;
];

-) instead of "Square Root" in "Time.i6t".
TagsNo tags attached.
Effect(serious/mild) Game compiles but misbehaves
Attached Files

- Relationships

-  Notes
(0001884)
curiousdannii (developer)
2012-10-06 19:47

Confirmed the bug and the patch (for those values, not for every value!).
(0002142)
climbingstars (reporter)
2013-10-13 13:16

A slightly tidier version of the patch above.

Include (-

[ SquareRoot num op res one;
op = num;
if (num < 0) { RunTimeProblem(RTP_NEGATIVEROOT); return 1; }
! "one" starts at the highest power of four <= the argument.
for (one = WORD_NEXTTOHIGHBIT: one > op: one = one/4) ;
while (one ~= 0) {
!print "Round: op = ", op, " | res = ", res, " | res**2 = ", res*res, " | one = ", one, "^";
if (op >= res + one) {
op = op - res - one;
res = res/2;
res = res + one;
}
else {
res = res/2;
}
one = one/4;
}
!print "Round: op = ", op, " | res = ", res, " | res**2 = ", res*res, " | one = ", one, "^";
!print "Res is ", res, "^";
return res;
];

-) instead of "Square Root" in "Time.i6t".
(0002271)
graham (administrator)
2014-01-12 06:46

The patch is adopted, with many thanks.

- Issue History
Date Modified Username Field Change
2012-10-06 15:04 climbingstars New Issue
2012-10-06 19:47 curiousdannii Note Added: 0001884
2012-10-06 19:47 curiousdannii Status new => confirmed
2013-10-13 13:16 climbingstars Note Added: 0002142
2014-01-12 06:46 graham Note Added: 0002271
2014-01-12 06:46 graham Status confirmed => resolved
2014-01-12 06:46 graham Resolution open => fixed
2014-01-12 06:46 graham Assigned To => graham
2014-05-07 07:34 jmcgrew Fixed in Version => 6L02
2014-05-07 07:34 jmcgrew Status resolved => closed


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker