File: real_test.go

package info (click to toggle)
golang-gopkg-asn1-ber.v1 1.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: makefile: 5
file content (31 lines) | stat: -rw-r--r-- 536 bytes parent folder | download | duplicates (2)
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
package ber

import (
	"math"
	"testing"
)

var negativeZero = math.Copysign(0, -1)

func TestRealEncoding(t *testing.T) {
	for _, value := range []float64{
		0.15625,
		-0.15625,
		math.Inf(1),
		math.Inf(-1),
		math.NaN(),
		negativeZero,
		0.0,
	} {
		enc := encodeFloat(value)
		dec, err := ParseReal(enc)
		if err != nil {
			t.Errorf("Failed to decode %f (%v): %s", value, enc, err)
		}
		if dec != value {
			if !(math.IsNaN(dec) && math.IsNaN(value)) {
				t.Errorf("decoded value != orig: %f <=> %f", value, dec)
			}
		}
	}
}