Arithmetic/Integer: Difference between revisions
Content added Content deleted
(Added Terraform Implementation) |
|||
Line 5,273: | Line 5,273: | ||
Also, it's important to surround the arguments to the <code>expr</code> in braces, especially when any of the parts of the expression are not literal constants. Discussion of this is on [http://wiki.tcl.tk/10225 The Tcler's Wiki]. |
Also, it's important to surround the arguments to the <code>expr</code> in braces, especially when any of the parts of the expression are not literal constants. Discussion of this is on [http://wiki.tcl.tk/10225 The Tcler's Wiki]. |
||
=={{header|Terraform}}== |
|||
HCL doesn't have an exponentiation operator and even integer division is contrived as shown in the code, but at least it prints the output variables alphabetically without any effort....... |
|||
<lang terraform> |
|||
#Aamrun, 15th August 2022 |
|||
variable "a" { |
|||
type = number |
|||
} |
|||
variable "b" { |
|||
type = number |
|||
} |
|||
output "Sum" { |
|||
value = var.a + var.b |
|||
} |
|||
output "Difference" { |
|||
value = var.a - var.b |
|||
} |
|||
output "Product" { |
|||
value = var.a * var.b |
|||
} |
|||
output "Quotient" { |
|||
value = floor(var.a / var.b) |
|||
} |
|||
output "Remainder" { |
|||
value = var.a % var.b |
|||
} |
|||
<lang> |
|||
The floor function rounds to the closest lowest integer. Invocation and output are as below : |
|||
{{out}} |
|||
<pre> |
|||
$ terraform apply -var="a=19" -var="b=7" -auto-approve |
|||
Changes to Outputs: |
|||
+ Difference = 12 |
|||
+ Product = 133 |
|||
+ Quotient = 2 |
|||
+ Remainder = 5 |
|||
+ Sum = 26 |
|||
You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure. |
|||
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. |
|||
Outputs: |
|||
Difference = 12 |
|||
Product = 133 |
|||
Quotient = 2 |
|||
Remainder = 5 |
|||
Sum = 26 |
|||
$ |
|||
</pre> |
|||
=={{header|TI-83 BASIC}}== |
=={{header|TI-83 BASIC}}== |