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

feat(number)!: default to high precision float #1675

Merged
merged 17 commits into from
Jan 30, 2023

Conversation

matthewmayer
Copy link
Contributor

@matthewmayer matthewmayer commented Dec 19, 2022

fix #1655

Note in order to reduce unexpected changes, i made a new code path for the default case when precision is not passed which grabs a float from Mersenne directly, while keeping the old logic intact (going via an integer) when a precision is pased.

I also added {precision: 0.01} in a few places in the code where float() was previously used to avoid unnecessary changes.

@matthewmayer matthewmayer requested a review from a team as a code owner December 19, 2022 07:58
@codecov
Copy link

codecov bot commented Dec 19, 2022

Codecov Report

Merging #1675 (79eda17) into next (0663048) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 79eda17 differs from pull request most recent head b9af667. Consider uploading reports for the commit b9af667 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #1675   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files        2340     2340           
  Lines      234254   234260    +6     
  Branches     1112     1116    +4     
=======================================
+ Hits       233421   233427    +6     
  Misses        812      812           
  Partials       21       21           
Impacted Files Coverage Δ
src/internal/mersenne/mersenne.ts 100.00% <100.00%> (ø)
src/modules/color/index.ts 99.79% <100.00%> (ø)
src/modules/number/index.ts 100.00% <100.00%> (ø)

@matthewmayer matthewmayer requested a review from a team December 19, 2022 10:56
@import-brain import-brain added c: feature Request for new feature p: 1-normal Nothing urgent labels Dec 20, 2022
matthewmayer and others added 3 commits January 23, 2023 15:36
# Conflicts:
#	test/__snapshots__/number.spec.ts.snap
Co-authored-by: Shinigami <chrissi92@hotmail.de>
@ST-DDT
Copy link
Member

ST-DDT commented Jan 23, 2023

Looks like we broke a test.

@ST-DDT ST-DDT added this to the v8.0 - Module Re-Shuffling milestone Jan 23, 2023
@ST-DDT ST-DDT added s: accepted Accepted feature / Confirmed bug m: number Something is referring to the number module labels Jan 23, 2023
@matthewmayer
Copy link
Contributor Author

I don't think that test makes much sense (precision 0)

Probably throwing an error is better

@matthewmayer
Copy link
Contributor Author

Some weird error with codecov on CI

@ST-DDT
Copy link
Member

ST-DDT commented Jan 23, 2023

I don't think that test makes much sense (precision 0)

Probably throwing an error is better

Mhh, a float with a precision of zero is an int.
I would still call it a valid value, but IMO that is not that important.
What do the others think?

@matthewmayer
Copy link
Contributor Author

I don't think that test makes much sense (precision 0)
Probably throwing an error is better

Mhh, a float with a precision of zero is an int. I would still call it a valid value, but IMO that is not that important. What do the others think?

no, a float with precision 1 is an int

@ST-DDT
Copy link
Member

ST-DDT commented Jan 23, 2023

no, a float with precision 1 is an int

Oh yeah, you are totally right.

Do we have a test that ensures the following

const actual = faker.number.float({precision: 1, ?});
expect(actual).toSatisfy(Number.isInteger);

?

@xDivisionByZerox xDivisionByZerox added the breaking change Cannot be merged when next version is not a major release label Jan 29, 2023
@xDivisionByZerox xDivisionByZerox changed the title feat(number): default to high precision float feat(number)!: default to high precision float Jan 29, 2023
@matthewmayer
Copy link
Contributor Author

i don't think this needs the breaking change label? Because this is only applied to faker.number.float() which is new in 8.0.0, not the old faker.datatype.float()

@ST-DDT ST-DDT removed the needs rebase There is a merge conflict label Jan 30, 2023
ST-DDT
ST-DDT previously approved these changes Jan 30, 2023
@xDivisionByZerox
Copy link
Member

xDivisionByZerox commented Jan 30, 2023

i don't think this needs the breaking change label? Because this is only applied to faker.number.float() which is new in 8.0.0, not the old faker.datatype.float()

You did call it a breaking change yourself. Even if only in a private function. Please be consistent whether you want to support JS or not! If yes, this is a breaking change for JS users since the way mersenne returns values was changed.

Edit: Thats exactly why I hate mixing points of interest in PRs! This change could have been done without touching mersenne in any way.

@Shinigami92
Copy link
Member

i don't think this needs the breaking change label? Because this is only applied to faker.number.float() which is new in 8.0.0, not the old faker.datatype.float()

You did call it a breaking change yourself. Even if only in a private function. Please be consistent whether you want to support JS or not! If yes, this is a breaking change for JS users since the way mersenne returns values was changed.

Edit: Thats exactly why I hate mixing points of interest in PRs! This change could have been done without touching mersenne in any way.

TBH I understand @xDivisionByZerox points here
I think it is good to mark this as breaking change anyway, because it affects a lot of other method calls inside faker like color.rgb.

I also understand that it might sometimes be better to make smaller PRs and split them, but for now I'm fine with the current state (except the english spelling in JSDoc), but then I can approve this 👍

Co-authored-by: Shinigami <chrissi92@hotmail.de>
@matthewmayer
Copy link
Contributor Author

There's not really a good definition of breaking change. You have to use your common sense as every change is a breaking change if your workflow is weird enough!

Anyway since this IS landing in a major release, whether it is breaking or not is moot.

https://xkcd.com/1172/

@Shinigami92 Shinigami92 enabled auto-merge (squash) January 30, 2023 13:13
@Shinigami92 Shinigami92 merged commit 1ebbead into faker-js:next Jan 30, 2023
@matthewmayer matthewmayer deleted the feature/high-precision-floats branch January 30, 2023 15:36
matthewmayer pushed a commit to matthewmayer/faker that referenced this pull request Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Cannot be merged when next version is not a major release c: feature Request for new feature m: number Something is referring to the number module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

change default precision of faker.number.float
5 participants