OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [math/] [frexp.go] - Blame information for rev 861

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package math
6
 
7
// Frexp breaks f into a normalized fraction
8
// and an integral power of two.
9
// It returns frac and exp satisfying f == frac × 2**exp,
10
// with the absolute value of frac in the interval [½, 1).
11
//
12
// Special cases are:
13
//      Frexp(±0) = ±0, 0
14
//      Frexp(±Inf) = ±Inf, 0
15
//      Frexp(NaN) = NaN, 0
16
func Frexp(f float64) (frac float64, exp int) {
17
        return frexp(f)
18
}
19
 
20
func frexp(f float64) (frac float64, exp int) {
21
        // special cases
22
        switch {
23
        case f == 0:
24
                return f, 0 // correctly return -0
25
        case IsInf(f, 0) || IsNaN(f):
26
                return f, 0
27
        }
28
        f, exp = normalize(f)
29
        x := Float64bits(f)
30
        exp += int((x>>shift)&mask) - bias + 1
31
        x &^= mask << shift
32
        x |= (-1 + bias) << shift
33
        frac = Float64frombits(x)
34
        return
35
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.