-
Notifications
You must be signed in to change notification settings - Fork 97
types/basetypes: Fix Float64Attribute precision comparisons #817
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
Conversation
Co-authored-by: Brian Flad <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 🚀
Co-authored-by: Brian Flad <[email protected]>
Oh wow, surprised that |
Fix included in terraform-plugin-framework v1.3.4 (via hashicorp/terraform-plugin-framework#817) - Closes #335
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #815
Related corner tests: hashicorp/terraform-provider-corner#170
Context
Terraform core's
number
type can store up to 512 bits of precision for floating numbers. This level of precision is typically only encountered when performing an arithmetic operation like below:$ terraform console > 1 - 0.99 0.010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003
The
Float64Attribute
underlying value of Go's built-infloat64
type was losing this precision and responding with invalid plan value errors seen in #815 .Solution
This PR replaces the underlying value of
Float64Attribute
with a*big.Float
type, which is already supported interraform-plugin-go
. Semantic equality logic has also been implemented to ensure thatComputed
values do not replace more precise prior values.