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

Subversion Repositories openrisc

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

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
// Ldexp is the inverse of Frexp.
8
// It returns frac × 2**exp.
9
//
10
// Special cases are:
11
//      Ldexp(±0, exp) = ±0
12
//      Ldexp(±Inf, exp) = ±Inf
13
//      Ldexp(NaN, exp) = NaN
14
 
15
//extern ldexp
16
func libc_ldexp(float64, int) float64
17
 
18
func Ldexp(frac float64, exp int) float64 {
19
        return libc_ldexp(frac, exp)
20
}
21
 
22
func ldexp(frac float64, exp int) float64 {
23
        // special cases
24
        switch {
25
        case frac == 0:
26
                return frac // correctly return -0
27
        case IsInf(frac, 0) || IsNaN(frac):
28
                return frac
29
        }
30
        frac, e := normalize(frac)
31
        exp += e
32
        x := Float64bits(frac)
33
        exp += int(x>>shift)&mask - bias
34
        if exp < -1074 {
35
                return Copysign(0, frac) // underflow
36
        }
37
        if exp > 1023 { // overflow
38
                if frac < 0 {
39
                        return Inf(-1)
40
                }
41
                return Inf(1)
42
        }
43
        var m float64 = 1
44
        if exp < -1022 { // denormal
45
                exp += 52
46
                m = 1.0 / (1 << 52) // 2**-52
47
        }
48
        x &^= mask << shift
49
        x |= uint64(exp+bias) << shift
50
        return m * Float64frombits(x)
51
}

powered by: WebSVN 2.1.0

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