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(math): add LegacyDecMut API. #18099

Closed
wants to merge 4 commits into from
Closed

feat(math): add LegacyDecMut API. #18099

wants to merge 4 commits into from

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Oct 12, 2023

Description

Closes: #18066


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

import "math/big"

// LegacyDecMut is a wrapper around big.Int with an unsafe and mutable API
type LegacyDecMut big.Int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

some problem with the approach is that it'd be now possible to create an overflowed dec by doing LegacyDecMut(overflowedBigInt).

Is this a problem?

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

For the benchmarks, please ensure that each iteration has deterministic final results and if you need to turn off benchmarking for noisy operations, you can invoke b.StopTimer() then b.StartTimer() after to continue benchmarking. Please see my review and thank you @testinginprod

Comment on lines +28 to +32
d := LegacyMustNewDecFromStr("123456789.123456789")
b.ResetTimer()
for i := 0; i < b.N; i++ {
sink = d.NegMut()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The current code will just change signs and the number of b.N will define the final results non-deterministically,
but we want every iteration to produce the exact same effect regardless of the number of b.N, let's do this instead.

	for i := 0; i < b.N; i++ {
                b.StopTimer()
	        d := LegacyMustNewDecFromStr("123456789.123456789")
                b.StartTimer()
		sink = d.NegMut()
	}

@julienrbrt
Copy link
Member

Could you revert this PR here as well: #17803?

@julienrbrt
Copy link
Member

julienrbrt commented Nov 6, 2023

As discussed on Slack, this will be rethought for math/v2 (ref #17750)

@julienrbrt julienrbrt closed this Nov 6, 2023
@julienrbrt julienrbrt deleted the tip/math/intmut branch November 6, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: seperate mutative from immutable api for Int
3 participants