Skip to content

"default word size" in the documentation for Util/Random #363

Description

@YawarRaza7349

Version

110.99.8 (Latest)

Operating System

  • Any
  • Linux
  • macOS
  • Windows
  • Other Unix

OS Version

No response

Processor

  • Any
  • Arm (using Rosetta)
  • PowerPC
  • Sparc
  • x86 (32-bit)
  • x86-64 (64-bit)
  • Other

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationfixed-in-110.99.9issues fixed in the 110.99.9 releasesmlnj-libGeneral issue with the SML/NJ Library or the Util component

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions