Created
February 17, 2015 19:26
-
-
Save ghodss/5215961c7acda2bda786 to your computer and use it in GitHub Desktop.
float64 not supported when marshalling to YAML in go-yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
"gopkg.in/v2/yaml" | |
) | |
type A struct { | |
F float64 | |
} | |
func main() { | |
f32 := A{math.MaxFloat32} | |
f64 := A{math.MaxFloat64} | |
y32, err := yaml.Marshal(f32) | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
} | |
y64, err := yaml.Marshal(f64) | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
} | |
fmt.Printf("Should contain %v: %v", math.MaxFloat32, string(y32)) | |
fmt.Printf("Should contain %v: %v", math.MaxFloat64, string(y64)) | |
} | |
// output: | |
Should contain 3.4028234663852886e+38: f: 3.4028235e+38 | |
Should contain 1.7976931348623157e+308: f: .inf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go-yaml/yaml#83