1// run
2
3// Copyright 2018 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9import (
10	"math"
11)
12
13type S struct {
14	u int64
15	n int32
16}
17
18func F1(f float64) *S {
19	s := f
20	pf := math.Copysign(f, 1)
21	u := math.Floor(pf)
22	return &S{
23		u: int64(math.Copysign(u, s)),
24		n: int32(math.Copysign((pf-u)*1e9, s)),
25	}
26}
27
28func F2(f float64) *S {
29	s := f
30	f = math.Copysign(f, 1)
31	u := math.Floor(f)
32	return &S{
33		u: int64(math.Copysign(u, s)),
34		n: int32(math.Copysign((f-u)*1e9, s)),
35	}
36}
37
38func main() {
39	s1 := F1(-1)
40	s2 := F2(-1)
41	if *s1 != *s2 {
42		println("F1:", s1.u, s1.n)
43		println("F2:", s2.u, s2.n)
44		panic("different")
45	}
46}
47