Skip to content

Commit 16c4545

Browse files
committed
add atan()
1 parent a4ee4e1 commit 16c4545

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ function complement(A: Union | Interval): Union;
250250
| Tangent | `nsf.tan(A)` |
251251
| Arccos | `nsf.acos(A)` |
252252
| Arcsin | `nsf.asin(A)` |
253+
| Arctan | `nsf.atan(A)` |
253254

254255
</div>
255256

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export { overlap, disjoint, intersection, complement } from "./compare.ts";
44
export { Union, union, single, bounded, EMPTY, FULL } from "./union.ts";
55
export { add, sub, mul, div, neg } from "./arithmetic.ts";
66
export { abs, min, max, exp, log, pow, powInt, sqrt, sqinv, powIntInv } from "./math.ts";
7-
export { cos, sin, tan, acos, asin } from "./trigonometry.ts";
7+
export { cos, sin, tan, acos, asin, atan } from "./trigonometry.ts";

src/trigonometry.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,23 @@ export function iasin(X: Interval): Union {
139139

140140
export const uasin = makeUnaryOpUnion(iasin);
141141
export const asin = makeUnaryOpEither(uasin);
142+
143+
// ARCTAN
144+
145+
function leftAtan(x: number): number {
146+
if (x === 0) return 0;
147+
return prev(Math.atan(x));
148+
}
149+
150+
function rightAtan(x: number): number {
151+
if (x === 0) return 0;
152+
return next(Math.atan(x));
153+
}
154+
155+
export function iatan(X: Interval): Union {
156+
typeCheckIsInterval(X);
157+
return new Union([new Interval(leftAtan(X.lo), rightAtan(X.hi))]);
158+
}
159+
160+
export const uatan = makeUnaryOpUnion(iatan);
161+
export const atan = makeUnaryOpEither(uatan);

tests/trigonometry.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ describe("acos", () => {
259259

260260
assert.deepStrictEqual(nsf.acos(nsf.single(-1.2, -1.1)), nsf.EMPTY);
261261
assert.deepStrictEqual(nsf.acos(nsf.single(1.1, 1.2)), nsf.EMPTY);
262+
assert.deepStrictEqual(nsf.acos(nsf.EMPTY), nsf.EMPTY);
262263
});
263264

264265
describe("asin", () => {
@@ -304,4 +305,47 @@ describe("asin", () => {
304305

305306
assert.deepStrictEqual(nsf.asin(nsf.single(-1.2, -1.1)), nsf.EMPTY);
306307
assert.deepStrictEqual(nsf.asin(nsf.single(1.1, 1.2)), nsf.EMPTY);
308+
assert.deepStrictEqual(nsf.asin(nsf.EMPTY), nsf.EMPTY);
309+
});
310+
311+
describe("atan", () => {
312+
assert.deepStrictEqual(nsf.atan(nsf.single(0)), nsf.single(0));
313+
314+
assert.deepStrictEqual(
315+
nsf.atan(nsf.single(-0.1)),
316+
nsf.single(prev(Math.atan(-0.1)), next(Math.atan(-0.1)))
317+
);
318+
319+
assert.deepStrictEqual(
320+
nsf.atan(nsf.single(0.2)),
321+
nsf.single(prev(Math.atan(0.2)), next(Math.atan(0.2)))
322+
);
323+
324+
assert.deepStrictEqual(
325+
nsf.atan(nsf.single(0.2, 0.5)),
326+
nsf.single(prev(Math.atan(0.2)), next(Math.atan(0.5)))
327+
);
328+
329+
assert.deepStrictEqual(
330+
nsf.atan(nsf.single(-0.2, 0.5)),
331+
nsf.single(prev(Math.atan(-0.2)), next(Math.atan(0.5)))
332+
);
333+
334+
assert.deepStrictEqual(
335+
nsf.atan(nsf.single(-1.1, 1.1)),
336+
nsf.single(prev(Math.atan(-1.1)), next(Math.atan(1.1)))
337+
);
338+
339+
assert.deepStrictEqual(
340+
nsf.atan(nsf.single(-1.1, -0.5)),
341+
nsf.single(prev(Math.atan(-1.1)), next(Math.atan(-0.5)))
342+
);
343+
344+
assert.deepStrictEqual(
345+
nsf.atan(nsf.single(0.5, 1.5)),
346+
nsf.single(prev(Math.atan(0.5)), next(Math.atan(1.5)))
347+
);
348+
349+
assert.deepStrictEqual(nsf.atan(nsf.FULL), nsf.single(prev(-Math.PI / 2), next(Math.PI / 2)));
350+
assert.deepStrictEqual(nsf.atan(nsf.EMPTY), nsf.EMPTY);
307351
});

0 commit comments

Comments
 (0)