-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
66 lines (60 loc) · 1.2 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* This module contains functions to add / subtract / multiply and divide 2 numbers.
* @module mod.ts
*
* * ```ts
* import { add } from "@monishcm-jsr/hello-jsr";
*
* add (1, 2) // returns 3
* ```
*
*/
import * as complex from 'npm:complex@latest';
/**
*
* @param a first number
* @param b second number
* @returns addition of a and b
*/
export function add(a: number, b: number): number {
return a + b;
}
/**
*
* @param a first number
* @param b second number
* @returns difference of a and b
*/
export function subtract(a: number, b: number): number {
return a - b;
}
/**
*
* @param a first number
* @param b second number
* @returns product of a and b
*/
export function multiply(a: number, b: number): number {
return a * b;
}
/**
*
* @param a first number
* @param b second number
* @returns division of a and b
*/
export function divide(a: number, b: number): number {
if (b === 0) {
throw new Error("Cannot divide by zero");
}
return a / b;
}
/**
*
* @param a first complex number
* @param b second complex number
* @returns addition of a and b
*/
export function complexAdd(a: complex, b: complex): complex {
return complex.add(a, b);
}