Skip to content

Instantly share code, notes, and snippets.

@ghodss
Created February 17, 2015 19:26
Show Gist options
  • Save ghodss/5215961c7acda2bda786 to your computer and use it in GitHub Desktop.
Save ghodss/5215961c7acda2bda786 to your computer and use it in GitHub Desktop.
float64 not supported when marshalling to YAML in go-yaml
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
@ghodss
Copy link
Author

ghodss commented Feb 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment