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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2010 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
/*
8
        Hypot -- sqrt(p*p + q*q), but overflows only if the result does.
9
*/
10
 
11
// Hypot computes Sqrt(p*p + q*q), taking care to avoid
12
// unnecessary overflow and underflow.
13
//
14
// Special cases are:
15
//      Hypot(p, q) = +Inf if p or q is infinite
16
//      Hypot(p, q) = NaN if p or q is NaN
17
func Hypot(p, q float64) float64 {
18
        return hypot(p, q)
19
}
20
 
21
func hypot(p, q float64) float64 {
22
        // special cases
23
        switch {
24
        case IsInf(p, 0) || IsInf(q, 0):
25
                return Inf(1)
26
        case IsNaN(p) || IsNaN(q):
27
                return NaN()
28
        }
29
        if p < 0 {
30
                p = -p
31
        }
32
        if q < 0 {
33
                q = -q
34
        }
35
        if p < q {
36
                p, q = q, p
37
        }
38
        if p == 0 {
39
                return 0
40
        }
41
        q = q / p
42
        return p * Sqrt(1+q*q)
43
}

powered by: WebSVN 2.1.0

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