Skip to content

Commit af64388

Browse files
committed
fix(s1): avoid negative zero
1 parent 4373a5b commit af64388

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

s1/angle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const radians = (a: Angle): number => a
4646
/**
4747
* Returns the angle in degrees.
4848
*/
49-
export const degrees = (a: Angle): number => a / DEGREE
49+
export const degrees = (a: Angle): number => a / DEGREE || 0
5050

5151
/**
5252
* Returns the value rounded to nearest as an int32.

s1/angle_test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ describe('s1.angle', () => {
1919
// Check negative angles.
2020
equal(angle.degrees((-Math.PI / 2) * RADIAN), -90, '(-π/2 * Radian).Degrees() was %v, want -90')
2121
equal(angle.radians(-45 * DEGREE), -Math.PI / 4, '(-45 * Degree).Radians() was %v, want -π/4')
22+
23+
// zero(s)
24+
equal(angle.degrees(0), 0, 'positive zero')
25+
equal(angle.degrees(-0), 0, 'negative zero')
2226
})
2327

2428
test('E5/E6/E7 representation', (t) => {

0 commit comments

Comments
 (0)