...

Source file src/github.com/go-asn1-ber/asn1-ber/real_test.go

Documentation: github.com/go-asn1-ber/asn1-ber

     1  package ber
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  var negativeZero = math.Copysign(0, -1)
     9  
    10  func TestRealEncoding(t *testing.T) {
    11  	for _, value := range []float64{
    12  		0.15625,
    13  		-0.15625,
    14  		math.Inf(1),
    15  		math.Inf(-1),
    16  		math.NaN(),
    17  		negativeZero,
    18  		0.0,
    19  	} {
    20  		enc := encodeFloat(value)
    21  		dec, err := ParseReal(enc)
    22  		if err != nil {
    23  			t.Errorf("Failed to decode %f (%v): %s", value, enc, err)
    24  		}
    25  		if dec != value {
    26  			if !(math.IsNaN(dec) && math.IsNaN(value)) {
    27  				t.Errorf("decoded value != orig: %f <=> %f", value, dec)
    28  			}
    29  		}
    30  	}
    31  }
    32  

View as plain text