LargeWord's <, >, <=, and >= operators seem to be doing signed comparisons, contrary to their intended behavior (and the behavior of LargeWord.compare). A transcript follows -- note the last line:
Poly/ML RTS version I386-4.1.3 (13:57:33 Sep 30 2002) Copyright (c) 2002 CUTS and contributors. Running with heap parameters (h=10240K,ib=2048K,ip=100%,mb=6144K,mp=20%) Mapping /u/richards/local/i386/lib/poly/ML_dbase Poly/ML 4.1.3 Release
LargeWord.compare(0w1, 0wx7FFFFFFF);
val it = LESS : General.order
LargeWord.<=(0w1,0wx7FFFFFFF);
val it = true : bool
LargeWord.compare(0w1, 0wx80000000);
val it = LESS : General.order
LargeWord.<=(0w1,0wx80000000);
val it = false : bool
On Sunday, Jan 19, 2003, at 23:38 Europe/London, Christopher Richards wrote:
LargeWord's <, >, <=, and >= operators seem to be doing signed comparisons, contrary to their intended behavior (and the behavior of LargeWord.compare). A transcript follows -- note the last line:
Thanks for reporting this. Actually LargeWord is a double-precision version of Word (i.e. 60 bits on the Sparc and 62 bits on everything else) and there was a silly mistake in all the relational operators which meant that the comparison on the high order word was reversed. I've fixed it in my copy of the source and it will get included in the next release. In the meantime if anyone needs the fix I can post the diffs.
A related question concerns Word32. Poly/ML does not currently have a Word32 structure although many other implementations do. The LargeWord structure can normally be used except that this does not produce exactly the same results if arithmetic wraps round. It probably wouldn't be a lot of work to provide it. Has anyone found a pressing need for it?
David.
Chris> LargeWord's <, >, <=, and >= operators seem to be doing signed Chris> comparisons, contrary to their intended behavior (and the Chris> behavior of LargeWord.compare). A transcript follows -- note Chris> the last line:
David> Thanks for reporting this. Actually LargeWord is a David> double-precision version of Word (i.e. 60 bits on the Sparc and David> 62 bits on everything else) and there was a silly mistake in David> all the relational operators which meant that the comparison on David> the high order word was reversed. I've fixed it in my copy of David> the source and it will get included in the next release. In David> the meantime if anyone needs the fix I can post the diffs.
Yes, I'll be grateful if you do post the diff.
On Tuesday, Jan 21, 2003, at 15:54 Europe/London, Ian Zimmerman wrote:
David> Thanks for reporting this. Actually LargeWord is a David> double-precision version of Word (i.e. 60 bits on the Sparc and David> 62 bits on everything else) and there was a silly mistake in David> all the relational operators which meant that the comparison on David> the high order word was reversed. I've fixed it in my copy of David> the source and it will get included in the next release. In David> the meantime if anyone needs the fix I can post the diffs.
Yes, I'll be grateful if you do post the diff.
The file is basis/LargeWord.sml and the diffs are given below. The easiest way to create a fixed version of Poly/ML is probably to download the mlsource and basis sources, edit the file to fix the bug and do a complete rebuild.
David.
Index: basis/LargeWord.sml =================================================================== RCS file: /usr/cvsroot/basis/LargeWord.sml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -b -w -r1.11 -r1.12 --- basis/LargeWord.sml 28 Feb 2001 12:53:47 -0000 1.11 +++ basis/LargeWord.sml 21 Jan 2003 13:13:20 -0000 1.12 @@ -403,27 +403,27 @@
fun op > ({hi, lo}, {hi=hi', lo=lo'}) = case Word.compare (hi, hi') of - General.GREATER => false + General.GREATER => true | General.EQUAL => Word.>(lo, lo') - | General.LESS => true + | General.LESS => false
and op < ({hi, lo}, {hi=hi', lo=lo'}) = case Word.compare (hi, hi') of - General.GREATER => true + General.GREATER => false | General.EQUAL => Word.<(lo, lo') - | General.LESS => false + | General.LESS => true
and op >= ({hi, lo}, {hi=hi', lo=lo'}) = case Word.compare (hi, hi') of - General.GREATER => false + General.GREATER => true | General.EQUAL => Word.>=(lo, lo') - | General.LESS => true + | General.LESS => false
and op <= ({hi, lo}, {hi=hi', lo=lo'}) = case Word.compare (hi, hi') of - General.GREATER => true + General.GREATER => false | General.EQUAL => Word.<=(lo, lo') - | General.LESS => false + | General.LESS => true
and compare({hi, lo}, {hi=hi', lo=lo'}) = case Word.compare (hi, hi') of
Yes, I think it would be good to have Word32. In Twelf, we use Word6x to simulate Word32. It so happens that on our current constraint domain specification, proper wraparound is not important, but that may change.
- Frank
LargeWord's <, >, <=, and >= operators seem to be doing signed comparisons, contrary to their intended behavior (and the behavior of LargeWord.compare). A transcript follows -- note the last line:
Thanks for reporting this. Actually LargeWord is a double-precision version of Word (i.e. 60 bits on the Sparc and 62 bits on everything else) and there was a silly mistake in all the relational operators which meant that the comparison on the high order word was reversed. I've fixed it in my copy of the source and it will get included in the next release. In the meantime if anyone needs the fix I can post the diffs.
A related question concerns Word32. Poly/ML does not currently have a Word32 structure although many other implementations do. The LargeWord structure can normally be used except that this does not produce exactly the same results if arithmetic wraps round. It probably wouldn't be a lot of work to provide it. Has anyone found a pressing need for it?
David.
polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml