Skip to content

number.float is unable to return 1/max exactly #2361

@ST-DDT

Description

@ST-DDT

Pre-Checks

Describe the bug

faker.number.float() is unable to return 1.

Minimal reproduction code

it('should be able to return 1', () => {
  // @ts-expect-error: access private member field
  const mersenne = faker._mersenne;
  mersenne.next = () => 0.9999999999999999; // based on the definition of mersenne.next()
  const actual = faker.number.float();
  expect(actual).toBe(1); // 💥 fails
});

Additional Context

Originally part of:

Environment Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz
    Memory: 47.42 GB / 63.69 GB
  Binaries:
    Node: 18.17.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.7.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.5.1 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Spartan (44.22621.2134.0), Chromium (116.0.1938.62)
    Internet Explorer: 11.0.22621.1

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

pnpm

Metadata

Metadata

Assignees

Labels

c: docsImprovements or additions to documentationm: numberSomething is referring to the number modulep: 1-normalNothing urgent

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions