-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathNumeric_Functions.tf
137 lines (106 loc) · 5.03 KB
/
Numeric_Functions.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#*#*#*#*#*#*#*#*##*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
#* Terraform Functions - Numeric Functions *#
#*#*#*#*#*#*#*#*##*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
#--------------------------------------------------------------------------------------------------------------------
# abs()
# returns the absolute value of the given number. In other words, if the number is zero or positive then it is returned as-is, but if it is negative then it is multiplied by -1 to make it positive before returning it.
# Syntax: abs(number)
#--------------------------------------------------------------------------------------------------------------------
output "abs-output" {
description = "Print the output of abs function"
value = {
"positive" = abs(13)
"zero" = abs(0)
"negative" = abs(-482)
"float" = abs(-13.25)
}
}
# Interesting Observation: if you uncomment the below output, Terraform will crash because it cant serialize infinity(1/0) as Json.
// output "tf-crash" {
// value = abs(1/0)
// }
#--------------------------------------------------------------------------------------------------------------------
# ceil()
# Returns the closest whole number that is greater than or equal to the given value, which may be a fraction.
# Syntax: ceil(number)
#--------------------------------------------------------------------------------------------------------------------
output "ceil-output" {
description = "Print the output of ceil function"
value = {
"op1" = ceil(13)
"op2" = ceil(13.0)
"op3" = ceil(13.1)
"op4" = ceil(13.99999)
}
}
#--------------------------------------------------------------------------------------------------------------------
# floor()
# Returns the closest whole number that is less than or equal to the given value, which may be a fraction.
# Syntax: floor(number)
#--------------------------------------------------------------------------------------------------------------------
output "floor-output" {
description = "Print the output of floor function"
value = {
"op1" = floor(13)
"op2" = floor(13.0)
"op3" = floor(13.1)
"op4" = floor(13.99999)
}
}
#--------------------------------------------------------------------------------------------------------------------
# log()
# Returns the logarithm of a given number in a given base.
# Syntax: log(number, base)
#--------------------------------------------------------------------------------------------------------------------
output "log-output" {
description = "Print the output of log function"
value = {
"op1" = log(10,2)
"op2" = log(16,4)
}
}
#--------------------------------------------------------------------------------------------------------------------
# max()
# Takes one or more numbers and returns the greatest number from the set.
# Syntax: max(number1, number2, ...)
#--------------------------------------------------------------------------------------------------------------------
output "max-output" {
description = "Print the output of max function"
value = max(13, 25, 0, 1325, 482, 27, 19)
}
#--------------------------------------------------------------------------------------------------------------------
# min()
# Takes one or more numbers and returns the smallest number from the set.
# Syntax: min(number1, number2, ...)
#--------------------------------------------------------------------------------------------------------------------
output "min-output" {
description = "Print the output of min function"
value = min(13, 25, 1325, 482, 27, 19)
}
#--------------------------------------------------------------------------------------------------------------------
# pow()
# Calculates an exponent, by raising its first argument to the power of the second argument.
# Syntax: pow(number1, number2)
#--------------------------------------------------------------------------------------------------------------------
output "pow-output" {
description = "Print the output of pow function"
value = {
"op1" = pow(13,2)
"op2" = pow(5,0)
"op3" = pow(0,5)
"op4" = pow(0,0)
}
}
#--------------------------------------------------------------------------------------------------------------------
# signum()
# Determines the sign of a number, returning a number between -1 and 1 to represent the sign.
# Syntax: signum(number)
#--------------------------------------------------------------------------------------------------------------------
output "signum-output" {
description = "Print the output of signum function"
value = {
"op1" = signum(0)
"op2" = signum(13)
"op3" = signum(-13)
}
}