Version
110.99.8 (Latest)
Operating System
OS Version
No response
Processor
System Component
SML/NJ Library
Severity
Cosmetic
Description
The documentation of the Random module of the SML/NJ library uses the terms "native word size" and "default word size". What does "default word size" mean here? If it just means "native word size minus 1" then it would be clearer to just say that.
If it's supposed to mean "the size of the type assigned to the global unqualified word type" — as it does in the docs for MONO_HASH_TABLE —, then the implementation does not account for this. For example, on MLton, where the unqualified word defaults to 32-bits, if the native word size is 64-bits, then randInt generates a random 63-bit word and calls toIntX on it (which is actually based on the default int size, not word size, though MLton's default int happens to also be 32-bits), thus Overflowing if the result doesn't fit in the 32-bit int. Based on the docs, one would expect it to instead always generate a number between -2^30 and 2^30 - 1 and thus never overflow.
It would probably be easier to just change the docs to change "default word size" to "native word size minus 1" because you'd technically also need to account for the case where the default word size is larger than the native word size, where you'd need to generate multiple random words and yadda yadda yadda (or you could ignore this niche case, I guess). I don't know if the SML spec guarantees properties about relative sizes of some types, which could make some (not all) concerns here moot.
Transcript
No response
Expected Behavior
No response
Steps to Reproduce
See MLton/mlton#617
Additional Information
No response
Email address
ysr7349@rit.edu
Version
110.99.8 (Latest)
Operating System
OS Version
No response
Processor
System Component
SML/NJ Library
Severity
Cosmetic
Description
The documentation of the Random module of the SML/NJ library uses the terms "native word size" and "default word size". What does "default word size" mean here? If it just means "native word size minus 1" then it would be clearer to just say that.
If it's supposed to mean "the size of the type assigned to the global unqualified
wordtype" — as it does in the docs forMONO_HASH_TABLE—, then the implementation does not account for this. For example, on MLton, where the unqualifiedworddefaults to 32-bits, if the native word size is 64-bits, thenrandIntgenerates a random 63-bit word and callstoIntXon it (which is actually based on the defaultintsize, notwordsize, though MLton's defaultinthappens to also be 32-bits), thusOverflowing if the result doesn't fit in the 32-bitint. Based on the docs, one would expect it to instead always generate a number between -2^30 and 2^30 - 1 and thus never overflow.It would probably be easier to just change the docs to change "default word size" to "native word size minus 1" because you'd technically also need to account for the case where the default word size is larger than the native word size, where you'd need to generate multiple random words and yadda yadda yadda (or you could ignore this niche case, I guess). I don't know if the SML spec guarantees properties about relative sizes of some types, which could make some (not all) concerns here moot.
Transcript
No response
Expected Behavior
No response
Steps to Reproduce
See MLton/mlton#617
Additional Information
No response
Email address
ysr7349@rit.edu