aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/value_init.go
diff options
context:
space:
mode:
authorNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
committerNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
commit107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch)
treeca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/zclconf/go-cty/cty/value_init.go
parent844b5a68d8af4791755b8f0ad293cc99f5959183 (diff)
downloadterraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/value_init.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/value_init.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/value_init.go b/vendor/github.com/zclconf/go-cty/cty/value_init.go
index 495a83e..3deeba3 100644
--- a/vendor/github.com/zclconf/go-cty/cty/value_init.go
+++ b/vendor/github.com/zclconf/go-cty/cty/value_init.go
@@ -30,6 +30,44 @@ func NumberVal(v *big.Float) Value {
30 } 30 }
31} 31}
32 32
33// ParseNumberVal returns a Value of type number produced by parsing the given
34// string as a decimal real number. To ensure that two identical strings will
35// always produce an equal number, always use this function to derive a number
36// from a string; it will ensure that the precision and rounding mode for the
37// internal big decimal is configured in a consistent way.
38//
39// If the given string cannot be parsed as a number, the returned error has
40// the message "a number is required", making it suitable to return to an
41// end-user to signal a type conversion error.
42//
43// If the given string contains a number that becomes a recurring fraction
44// when expressed in binary then it will be truncated to have a 512-bit
45// mantissa. Note that this is a higher precision than that of a float64,
46// so coverting the same decimal number first to float64 and then calling
47// NumberFloatVal will not produce an equal result; the conversion first
48// to float64 will round the mantissa to fewer than 512 bits.
49func ParseNumberVal(s string) (Value, error) {
50 // Base 10, precision 512, and rounding to nearest even is the standard
51 // way to handle numbers arriving as strings.
52 f, _, err := big.ParseFloat(s, 10, 512, big.ToNearestEven)
53 if err != nil {
54 return NilVal, fmt.Errorf("a number is required")
55 }
56 return NumberVal(f), nil
57}
58
59// MustParseNumberVal is like ParseNumberVal but it will panic in case of any
60// error. It can be used during initialization or any other situation where
61// the given string is a constant or otherwise known to be correct by the
62// caller.
63func MustParseNumberVal(s string) Value {
64 ret, err := ParseNumberVal(s)
65 if err != nil {
66 panic(err)
67 }
68 return ret
69}
70
33// NumberIntVal returns a Value of type Number whose internal value is equal 71// NumberIntVal returns a Value of type Number whose internal value is equal
34// to the given integer. 72// to the given integer.
35func NumberIntVal(v int64) Value { 73func NumberIntVal(v int64) Value {