Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(number): improve float generation for precisions of form 10^-n #2581

Merged
merged 10 commits into from
Dec 27, 2023

Conversation

matthewmayer
Copy link
Contributor

@matthewmayer matthewmayer commented Dec 17, 2023

fix #2567

Changes the way that the 1/precision is calculated in faker.number.float() using Math.log10 and Math.pow

This ensures that if precision is 0.00001, you get exactly 100000 for example, not 99999.99999999999

Copy link

codecov bot commented Dec 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (24482a3) 99.57% compared to head (60bd52c) 99.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2581      +/-   ##
==========================================
- Coverage   99.57%   99.56%   -0.01%     
==========================================
  Files        2807     2807              
  Lines      250374   250379       +5     
  Branches     1141     1137       -4     
==========================================
- Hits       249314   249301      -13     
- Misses       1032     1050      +18     
  Partials       28       28              
Files Coverage Δ
src/modules/number/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@matthewmayer matthewmayer changed the title fix(number): change expected result for precisions of form 0.000...1 fix(number): change expected result of faker.number.float() for precisions of form 0.000...1 Dec 17, 2023
@matthewmayer matthewmayer changed the title fix(number): change expected result of faker.number.float() for precisions of form 0.000...1 fix(number): change expected result of faker.number.float() for precisions of form 10^-n Dec 17, 2023
@matthewmayer
Copy link
Contributor Author

Note this obviously conflicts with #2564, probably easiest to merge that first since it touches more code

src/modules/number/index.ts Outdated Show resolved Hide resolved
test/modules/number.spec.ts Outdated Show resolved Hide resolved
@ST-DDT
Copy link
Member

ST-DDT commented Dec 18, 2023

And thanks for tackling this ❤️

test/modules/number.spec.ts Outdated Show resolved Hide resolved
Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't have enough free time to look at the precision behavior yet.

src/modules/number/index.ts Outdated Show resolved Hide resolved
test/modules/number.spec.ts Outdated Show resolved Hide resolved
test/modules/number.spec.ts Outdated Show resolved Hide resolved
@ST-DDT ST-DDT added this to the vAnytime milestone Dec 20, 2023
@ST-DDT ST-DDT added c: bug Something isn't working p: 1-normal Nothing urgent m: number Something is referring to the number module labels Dec 20, 2023
@ST-DDT
Copy link
Member

ST-DDT commented Dec 20, 2023

Thanks for addressing all my comments 👍

@ST-DDT ST-DDT changed the title fix(number): change expected result of faker.number.float() for precisions of form 10^-n fix(number): improve float generation for precisions of form 10^-n Dec 27, 2023
@ST-DDT ST-DDT enabled auto-merge (squash) December 27, 2023 18:43
@ST-DDT ST-DDT merged commit 39c715d into faker-js:next Dec 27, 2023
20 checks passed
@ST-DDT ST-DDT linked an issue Jan 19, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working m: number Something is referring to the number module p: 1-normal Nothing urgent
Projects
None yet
2 participants