Skip to content

Commit

Permalink
refactor: use BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
soc221b committed Feb 22, 2025
1 parent a900efb commit 659fa09
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/modules/number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,22 @@ export class NumberModule extends SimpleModuleBase {
throw new FakerError(`Max ${max} should be larger than min ${min}.`);
}

if (multipleOf <= 0n) {
if (multipleOf <= BigInt(0)) {
throw new FakerError(`multipleOf should be greater than 0.`);
}

const effectiveMin =
min % multipleOf === 0n
min % multipleOf === BigInt(0)
? min / multipleOf
: 0n <= min
? min / multipleOf + 1n
: BigInt(0) <= min
? min / multipleOf + BigInt(1)
: min / multipleOf;
const effectiveMax =
max % multipleOf === 0n
max % multipleOf === BigInt(0)
? max / multipleOf
: 0n <= max
: BigInt(0) <= max
? max / multipleOf
: max / multipleOf - 1n;
: max / multipleOf - BigInt(1);

if (effectiveMin === effectiveMax) {
return effectiveMin * multipleOf;
Expand All @@ -472,7 +472,7 @@ export class NumberModule extends SimpleModuleBase {
allowLeadingZeros: true,
})
) %
(delta + 1n);
(delta + BigInt(1));
return (effectiveMin + offset) * multipleOf;
}

Expand Down

0 comments on commit 659fa09

Please sign in to comment.