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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [math/] [modf.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
// Modf returns integer and fractional floating-point numbers
8
// that sum to f.  Both values have the same sign as f.
9
//
10
// Special cases are:
11
//      Modf(±Inf) = ±Inf, NaN
12
//      Modf(NaN) = NaN, NaN
13
func Modf(f float64) (int float64, frac float64) {
14
        return modf(f)
15
}
16
 
17
func modf(f float64) (int float64, frac float64) {
18
        if f < 1 {
19
                if f < 0 {
20
                        int, frac = Modf(-f)
21
                        return -int, -frac
22
                }
23
                return 0, f
24
        }
25
 
26
        x := Float64bits(f)
27
        e := uint(x>>shift)&mask - bias
28
 
29
        // Keep the top 12+e bits, the integer part; clear the rest.
30
        if e < 64-12 {
31
                x &^= 1<<(64-12-e) - 1
32
        }
33
        int = Float64frombits(x)
34
        frac = f - int
35
        return
36
}

powered by: WebSVN 2.1.0

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