-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Add new interpolation function abs
.
#16168
Add new interpolation function abs
.
#16168
Conversation
Tests are passing:
|
Hi @vancluever, a Pull Request as discussed. There is one thing I would love to be able to solve - |
This commit adds new interpolation function `abs` which returns an absolute value for a given float. Having an ability to obtain an absolute value remove the need to use and abuse the `signum` function to achieve the same gaol. Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
704f688
to
8a0bd9e
Compare
As per the conversation with @vancluever, I moved |
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.
LGTM! Just adding @jbardin and @apparentlymart to confirm.
Also as an aside - we uncovered some inference here that seems a bit confusing when it comes to whole numbers expressed as floats, as @kwilczynski describes above. I'm not too sure where it happens (before or after interpolation), but a whole number expressed as say, 1.0
ends up getting turned into an int somewhere, and comes out as 1
, or at the very least gets displayed as an int when output.
At the very least it's kind of confusing in this context when the user wants to make sure they are getting a float back. Maybe some clarification is in order just to confirm? I'm trying to look to see exactly where this happens.
It's intentional that the string representation of a float representing a whole number doesn't have a fractional part. The distinction between int and float is actually planned to be removed in the future, since it doesn't really seem to be a useful distinction for things Terraform is generally used for. (more news on that to come soon.) Generally-speaking, any time a non-list/non-map value is moved between attributes via interpolation (as opposed to within an interpolation expression) it is always converted to a string, since Terraform Core treats all primitive types as strings today. That too is something that will change in future, as part of some type system work. For now though, "getting a float back" isn't really a meaningful concept... the best you can do is get a string representation of a number, which might later get converted back into a number again when passed to other functions. This looks fine to me, and does the best it can within the current constraints. Thanks for working on this, @kwilczynski! |
FWIW, I think under the hood things work as expected, it seems the behaviour is mainly just superficial. Nothing that I saw would indicate anything seriously breaking as a result of this... so I think it will behave correctly 👍 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This commit adds new interpolation function
abs
which returns an absolutevalue for a given float. Having an ability to obtain an absolute value remove
the need to use and abuse the
signum
function to achieve the same gaol.Signed-off-by: Krzysztof Wilczynski kw@linux.com