Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1077)

Delta Between Two Patch Sets: src/pkg/math/atan2.go

Issue 5484076: code review 5484076: pkg/math: undo manual inlining of IsInf and IsNaN (Closed)
Left Patch Set: Created 13 years, 4 months ago
Right Patch Set: diff -r 7c0d2f963500 https://go.googlecode.com/hg/ Created 13 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/math/asinh.go ('k') | src/pkg/math/atanh.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package math 5 package math
6 6
7 // Atan2 returns the arc tangent of y/x, using 7 // Atan2 returns the arc tangent of y/x, using
8 // the signs of the two to determine the quadrant 8 // the signs of the two to determine the quadrant
9 // of the return value. 9 // of the return value.
10 // 10 //
(...skipping 11 matching lines...) Expand all
22 // Atan2(+Inf, -Inf) = 3Pi/4 22 // Atan2(+Inf, -Inf) = 3Pi/4
23 // Atan2(-Inf, -Inf) = -3Pi/4 23 // Atan2(-Inf, -Inf) = -3Pi/4
24 // Atan2(y, +Inf) = 0 24 // Atan2(y, +Inf) = 0
25 // Atan2(y>0, -Inf) = +Pi 25 // Atan2(y>0, -Inf) = +Pi
26 // Atan2(y<0, -Inf) = -Pi 26 // Atan2(y<0, -Inf) = -Pi
27 // Atan2(+Inf, x) = +Pi/2 27 // Atan2(+Inf, x) = +Pi/2
28 // Atan2(-Inf, x) = -Pi/2 28 // Atan2(-Inf, x) = -Pi/2
29 func Atan2(y, x float64) float64 29 func Atan2(y, x float64) float64
30 30
31 func atan2(y, x float64) float64 { 31 func atan2(y, x float64) float64 {
32 // TODO(rsc): Remove manual inlining of IsNaN, IsInf
33 // when compiler does it for us
34 // special cases 32 // special cases
35 switch { 33 switch {
36 » case y != y || x != x: // IsNaN(y) || IsNaN(x): 34 » case IsNaN(y) || IsNaN(x):
37 return NaN() 35 return NaN()
38 case y == 0: 36 case y == 0:
39 if x >= 0 && !Signbit(x) { 37 if x >= 0 && !Signbit(x) {
40 return Copysign(0, y) 38 return Copysign(0, y)
41 } 39 }
42 return Copysign(Pi, y) 40 return Copysign(Pi, y)
43 case x == 0: 41 case x == 0:
44 return Copysign(Pi/2, y) 42 return Copysign(Pi/2, y)
45 » case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0): 43 » case IsInf(x, 0):
46 » » if x > MaxFloat64 { // IsInf(x, 1) { 44 » » if IsInf(x, 1) {
47 switch { 45 switch {
48 » » » case y < -MaxFloat64 || y > MaxFloat64: // IsInf(y, -1) || IsInf(y, 1): 46 » » » case IsInf(y, 0):
49 return Copysign(Pi/4, y) 47 return Copysign(Pi/4, y)
50 default: 48 default:
51 return Copysign(0, y) 49 return Copysign(0, y)
52 } 50 }
53 } 51 }
54 switch { 52 switch {
55 » » case y < -MaxFloat64 || y > MaxFloat64: // IsInf(y, -1) || IsInf (y, 1): 53 » » case IsInf(y, 0):
56 return Copysign(3*Pi/4, y) 54 return Copysign(3*Pi/4, y)
57 default: 55 default:
58 return Copysign(Pi, y) 56 return Copysign(Pi, y)
59 } 57 }
60 » case y < -MaxFloat64 || y > MaxFloat64: //IsInf(y, 0): 58 » case IsInf(y, 0):
61 return Copysign(Pi/2, y) 59 return Copysign(Pi/2, y)
62 } 60 }
63 61
64 // Call atan and determine the quadrant. 62 // Call atan and determine the quadrant.
65 q := Atan(y / x) 63 q := Atan(y / x)
66 if x < 0 { 64 if x < 0 {
67 if q <= 0 { 65 if q <= 0 {
68 return q + Pi 66 return q + Pi
69 } 67 }
70 return q - Pi 68 return q - Pi
71 } 69 }
72 return q 70 return q
73 } 71 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b