lite-math 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +19 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +51 -0
- package/LICENSE +21 -0
- package/README.md +213 -0
- package/app/globals.css +125 -0
- package/app/layout.tsx +27 -0
- package/app/page.tsx +7 -0
- package/components/theme-provider.tsx +11 -0
- package/components/ui/accordion.tsx +66 -0
- package/components/ui/alert-dialog.tsx +157 -0
- package/components/ui/alert.tsx +66 -0
- package/components/ui/aspect-ratio.tsx +11 -0
- package/components/ui/avatar.tsx +53 -0
- package/components/ui/badge.tsx +46 -0
- package/components/ui/breadcrumb.tsx +109 -0
- package/components/ui/button-group.tsx +83 -0
- package/components/ui/button.tsx +60 -0
- package/components/ui/calendar.tsx +213 -0
- package/components/ui/card.tsx +92 -0
- package/components/ui/carousel.tsx +241 -0
- package/components/ui/chart.tsx +353 -0
- package/components/ui/checkbox.tsx +32 -0
- package/components/ui/collapsible.tsx +33 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/context-menu.tsx +252 -0
- package/components/ui/dialog.tsx +143 -0
- package/components/ui/drawer.tsx +135 -0
- package/components/ui/dropdown-menu.tsx +257 -0
- package/components/ui/empty.tsx +104 -0
- package/components/ui/field.tsx +244 -0
- package/components/ui/form.tsx +167 -0
- package/components/ui/hover-card.tsx +44 -0
- package/components/ui/input-group.tsx +169 -0
- package/components/ui/input-otp.tsx +77 -0
- package/components/ui/input.tsx +21 -0
- package/components/ui/item.tsx +193 -0
- package/components/ui/kbd.tsx +28 -0
- package/components/ui/label.tsx +24 -0
- package/components/ui/menubar.tsx +276 -0
- package/components/ui/navigation-menu.tsx +166 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +48 -0
- package/components/ui/progress.tsx +31 -0
- package/components/ui/radio-group.tsx +45 -0
- package/components/ui/resizable.tsx +56 -0
- package/components/ui/scroll-area.tsx +58 -0
- package/components/ui/select.tsx +185 -0
- package/components/ui/separator.tsx +28 -0
- package/components/ui/sheet.tsx +139 -0
- package/components/ui/sidebar.tsx +726 -0
- package/components/ui/skeleton.tsx +13 -0
- package/components/ui/slider.tsx +63 -0
- package/components/ui/sonner.tsx +25 -0
- package/components/ui/spinner.tsx +16 -0
- package/components/ui/switch.tsx +31 -0
- package/components/ui/table.tsx +116 -0
- package/components/ui/tabs.tsx +66 -0
- package/components/ui/textarea.tsx +18 -0
- package/components/ui/toast.tsx +129 -0
- package/components/ui/toaster.tsx +35 -0
- package/components/ui/toggle-group.tsx +73 -0
- package/components/ui/toggle.tsx +47 -0
- package/components/ui/tooltip.tsx +61 -0
- package/components/ui/use-mobile.tsx +19 -0
- package/components/ui/use-toast.ts +191 -0
- package/components.json +21 -0
- package/dist/advanced/cube-root.d.ts +2 -0
- package/dist/advanced/cube-root.d.ts.map +1 -0
- package/dist/advanced/cube-root.js +4 -0
- package/dist/advanced/cube-root.js.map +1 -0
- package/dist/advanced/factorial.d.ts +2 -0
- package/dist/advanced/factorial.d.ts.map +1 -0
- package/dist/advanced/factorial.js +11 -0
- package/dist/advanced/factorial.js.map +1 -0
- package/dist/advanced/fibonacci.d.ts +2 -0
- package/dist/advanced/fibonacci.d.ts.map +1 -0
- package/dist/advanced/fibonacci.js +15 -0
- package/dist/advanced/fibonacci.js.map +1 -0
- package/dist/advanced/gcd.d.ts +2 -0
- package/dist/advanced/gcd.d.ts.map +1 -0
- package/dist/advanced/gcd.js +10 -0
- package/dist/advanced/gcd.js.map +1 -0
- package/dist/advanced/lcm.d.ts +2 -0
- package/dist/advanced/lcm.d.ts.map +1 -0
- package/dist/advanced/lcm.js +13 -0
- package/dist/advanced/lcm.js.map +1 -0
- package/dist/advanced/power.d.ts +2 -0
- package/dist/advanced/power.d.ts.map +1 -0
- package/dist/advanced/power.js +4 -0
- package/dist/advanced/power.js.map +1 -0
- package/dist/advanced/prime-check.d.ts +2 -0
- package/dist/advanced/prime-check.d.ts.map +1 -0
- package/dist/advanced/prime-check.js +14 -0
- package/dist/advanced/prime-check.js.map +1 -0
- package/dist/advanced/prime-list.d.ts +2 -0
- package/dist/advanced/prime-list.d.ts.map +1 -0
- package/dist/advanced/prime-list.js +14 -0
- package/dist/advanced/prime-list.js.map +1 -0
- package/dist/advanced/sqrt.d.ts +2 -0
- package/dist/advanced/sqrt.d.ts.map +1 -0
- package/dist/advanced/sqrt.js +6 -0
- package/dist/advanced/sqrt.js.map +1 -0
- package/dist/algebra/circle-area.d.ts +2 -0
- package/dist/algebra/circle-area.d.ts.map +1 -0
- package/dist/algebra/circle-area.js +4 -0
- package/dist/algebra/circle-area.js.map +1 -0
- package/dist/algebra/distance.d.ts +2 -0
- package/dist/algebra/distance.d.ts.map +1 -0
- package/dist/algebra/distance.js +4 -0
- package/dist/algebra/distance.js.map +1 -0
- package/dist/algebra/midpoint.d.ts +2 -0
- package/dist/algebra/midpoint.d.ts.map +1 -0
- package/dist/algebra/midpoint.js +4 -0
- package/dist/algebra/midpoint.js.map +1 -0
- package/dist/algebra/slope.d.ts +2 -0
- package/dist/algebra/slope.d.ts.map +1 -0
- package/dist/algebra/slope.js +6 -0
- package/dist/algebra/slope.js.map +1 -0
- package/dist/algebra/solve-linear.d.ts +2 -0
- package/dist/algebra/solve-linear.d.ts.map +1 -0
- package/dist/algebra/solve-linear.js +6 -0
- package/dist/algebra/solve-linear.js.map +1 -0
- package/dist/algebra/solve-quadratic.d.ts +2 -0
- package/dist/algebra/solve-quadratic.d.ts.map +1 -0
- package/dist/algebra/solve-quadratic.js +12 -0
- package/dist/algebra/solve-quadratic.js.map +1 -0
- package/dist/algebra/triangle-area.d.ts +2 -0
- package/dist/algebra/triangle-area.d.ts.map +1 -0
- package/dist/algebra/triangle-area.js +5 -0
- package/dist/algebra/triangle-area.js.map +1 -0
- package/dist/arithmetic/add.d.ts +2 -0
- package/dist/arithmetic/add.d.ts.map +1 -0
- package/dist/arithmetic/add.js +4 -0
- package/dist/arithmetic/add.js.map +1 -0
- package/dist/arithmetic/ceil.d.ts +2 -0
- package/dist/arithmetic/ceil.d.ts.map +1 -0
- package/dist/arithmetic/ceil.js +4 -0
- package/dist/arithmetic/ceil.js.map +1 -0
- package/dist/arithmetic/clamp.d.ts +2 -0
- package/dist/arithmetic/clamp.d.ts.map +1 -0
- package/dist/arithmetic/clamp.js +4 -0
- package/dist/arithmetic/clamp.js.map +1 -0
- package/dist/arithmetic/divide.d.ts +2 -0
- package/dist/arithmetic/divide.d.ts.map +1 -0
- package/dist/arithmetic/divide.js +6 -0
- package/dist/arithmetic/divide.js.map +1 -0
- package/dist/arithmetic/floor.d.ts +2 -0
- package/dist/arithmetic/floor.d.ts.map +1 -0
- package/dist/arithmetic/floor.js +4 -0
- package/dist/arithmetic/floor.js.map +1 -0
- package/dist/arithmetic/modulo.d.ts +2 -0
- package/dist/arithmetic/modulo.d.ts.map +1 -0
- package/dist/arithmetic/modulo.js +4 -0
- package/dist/arithmetic/modulo.js.map +1 -0
- package/dist/arithmetic/multiply.d.ts +2 -0
- package/dist/arithmetic/multiply.d.ts.map +1 -0
- package/dist/arithmetic/multiply.js +4 -0
- package/dist/arithmetic/multiply.js.map +1 -0
- package/dist/arithmetic/percentage.d.ts +2 -0
- package/dist/arithmetic/percentage.d.ts.map +1 -0
- package/dist/arithmetic/percentage.js +4 -0
- package/dist/arithmetic/percentage.js.map +1 -0
- package/dist/arithmetic/round.d.ts +2 -0
- package/dist/arithmetic/round.d.ts.map +1 -0
- package/dist/arithmetic/round.js +5 -0
- package/dist/arithmetic/round.js.map +1 -0
- package/dist/arithmetic/subtract.d.ts +2 -0
- package/dist/arithmetic/subtract.d.ts.map +1 -0
- package/dist/arithmetic/subtract.js +4 -0
- package/dist/arithmetic/subtract.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +277 -0
- package/dist/cli.js.map +1 -0
- package/dist/convert/c-to-f.d.ts +2 -0
- package/dist/convert/c-to-f.d.ts.map +1 -0
- package/dist/convert/c-to-f.js +4 -0
- package/dist/convert/c-to-f.js.map +1 -0
- package/dist/convert/deg-to-rad.d.ts +2 -0
- package/dist/convert/deg-to-rad.d.ts.map +1 -0
- package/dist/convert/deg-to-rad.js +4 -0
- package/dist/convert/deg-to-rad.js.map +1 -0
- package/dist/convert/f-to-c.d.ts +2 -0
- package/dist/convert/f-to-c.d.ts.map +1 -0
- package/dist/convert/f-to-c.js +4 -0
- package/dist/convert/f-to-c.js.map +1 -0
- package/dist/convert/km-to-miles.d.ts +2 -0
- package/dist/convert/km-to-miles.d.ts.map +1 -0
- package/dist/convert/km-to-miles.js +4 -0
- package/dist/convert/km-to-miles.js.map +1 -0
- package/dist/convert/miles-to-km.d.ts +2 -0
- package/dist/convert/miles-to-km.d.ts.map +1 -0
- package/dist/convert/miles-to-km.js +4 -0
- package/dist/convert/miles-to-km.js.map +1 -0
- package/dist/convert/rad-to-deg.d.ts +2 -0
- package/dist/convert/rad-to-deg.d.ts.map +1 -0
- package/dist/convert/rad-to-deg.js +4 -0
- package/dist/convert/rad-to-deg.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/random/random-array.d.ts +2 -0
- package/dist/random/random-array.d.ts.map +1 -0
- package/dist/random/random-array.js +4 -0
- package/dist/random/random-array.js.map +1 -0
- package/dist/random/random-float.d.ts +2 -0
- package/dist/random/random-float.d.ts.map +1 -0
- package/dist/random/random-float.js +4 -0
- package/dist/random/random-float.js.map +1 -0
- package/dist/random/random-from-array.d.ts +2 -0
- package/dist/random/random-from-array.d.ts.map +1 -0
- package/dist/random/random-from-array.js +4 -0
- package/dist/random/random-from-array.js.map +1 -0
- package/dist/random/random-int.d.ts +2 -0
- package/dist/random/random-int.d.ts.map +1 -0
- package/dist/random/random-int.js +4 -0
- package/dist/random/random-int.js.map +1 -0
- package/dist/statistics/mean.d.ts +2 -0
- package/dist/statistics/mean.d.ts.map +1 -0
- package/dist/statistics/mean.js +6 -0
- package/dist/statistics/mean.js.map +1 -0
- package/dist/statistics/median.d.ts +2 -0
- package/dist/statistics/median.d.ts.map +1 -0
- package/dist/statistics/median.js +8 -0
- package/dist/statistics/median.js.map +1 -0
- package/dist/statistics/mode.d.ts +2 -0
- package/dist/statistics/mode.d.ts.map +1 -0
- package/dist/statistics/mode.js +13 -0
- package/dist/statistics/mode.js.map +1 -0
- package/dist/statistics/product-array.d.ts +2 -0
- package/dist/statistics/product-array.d.ts.map +1 -0
- package/dist/statistics/product-array.js +4 -0
- package/dist/statistics/product-array.js.map +1 -0
- package/dist/statistics/range.d.ts +2 -0
- package/dist/statistics/range.d.ts.map +1 -0
- package/dist/statistics/range.js +6 -0
- package/dist/statistics/range.js.map +1 -0
- package/dist/statistics/std-dev.d.ts +2 -0
- package/dist/statistics/std-dev.d.ts.map +1 -0
- package/dist/statistics/std-dev.js +10 -0
- package/dist/statistics/std-dev.js.map +1 -0
- package/dist/statistics/sum-array.d.ts +2 -0
- package/dist/statistics/sum-array.d.ts.map +1 -0
- package/dist/statistics/sum-array.js +4 -0
- package/dist/statistics/sum-array.js.map +1 -0
- package/dist/statistics/variance.d.ts +2 -0
- package/dist/statistics/variance.d.ts.map +1 -0
- package/dist/statistics/variance.js +7 -0
- package/dist/statistics/variance.js.map +1 -0
- package/examples/advanced-examples.ts +31 -0
- package/examples/algebra-examples.ts +24 -0
- package/examples/arithmetic-examples.ts +24 -0
- package/examples/conversion-examples.ts +24 -0
- package/examples/statistics-examples.ts +29 -0
- package/hooks/use-mobile.ts +19 -0
- package/hooks/use-toast.ts +191 -0
- package/jest.config.js +15 -0
- package/lib/utils.ts +6 -0
- package/next.config.mjs +11 -0
- package/package.json +110 -0
- package/postcss.config.mjs +8 -0
- package/public/apple-icon.png +0 -0
- package/public/icon-dark-32x32.png +0 -0
- package/public/icon-light-32x32.png +0 -0
- package/public/icon.svg +26 -0
- package/public/placeholder-logo.png +0 -0
- package/public/placeholder-logo.svg +1 -0
- package/public/placeholder-user.jpg +0 -0
- package/public/placeholder.jpg +0 -0
- package/public/placeholder.svg +1 -0
- package/src/advanced/cube-root.ts +8 -0
- package/src/advanced/factorial.ts +12 -0
- package/src/advanced/fibonacci.ts +16 -0
- package/src/advanced/gcd.ts +14 -0
- package/src/advanced/lcm.ts +18 -0
- package/src/advanced/power.ts +9 -0
- package/src/advanced/prime-check.ts +14 -0
- package/src/advanced/prime-list.ts +16 -0
- package/src/advanced/sqrt.ts +9 -0
- package/src/algebra/circle-area.ts +8 -0
- package/src/algebra/distance.ts +11 -0
- package/src/algebra/midpoint.ts +11 -0
- package/src/algebra/slope.ts +12 -0
- package/src/algebra/solve-linear.ts +10 -0
- package/src/algebra/solve-quadratic.ts +15 -0
- package/src/algebra/triangle-area.ts +11 -0
- package/src/arithmetic/add.ts +9 -0
- package/src/arithmetic/ceil.ts +8 -0
- package/src/arithmetic/clamp.ts +10 -0
- package/src/arithmetic/divide.ts +11 -0
- package/src/arithmetic/floor.ts +8 -0
- package/src/arithmetic/modulo.ts +9 -0
- package/src/arithmetic/multiply.ts +9 -0
- package/src/arithmetic/percentage.ts +9 -0
- package/src/arithmetic/round.ts +10 -0
- package/src/arithmetic/subtract.ts +9 -0
- package/src/cli.ts +321 -0
- package/src/convert/c-to-f.ts +8 -0
- package/src/convert/deg-to-rad.ts +8 -0
- package/src/convert/f-to-c.ts +8 -0
- package/src/convert/km-to-miles.ts +8 -0
- package/src/convert/miles-to-km.ts +8 -0
- package/src/convert/rad-to-deg.ts +8 -0
- package/src/index.ts +49 -0
- package/src/random/random-array.ts +10 -0
- package/src/random/random-float.ts +9 -0
- package/src/random/random-from-array.ts +8 -0
- package/src/random/random-int.ts +9 -0
- package/src/statistics/mean.ts +9 -0
- package/src/statistics/median.ts +11 -0
- package/src/statistics/mode.ts +16 -0
- package/src/statistics/product-array.ts +8 -0
- package/src/statistics/range.ts +9 -0
- package/src/statistics/std-dev.ts +14 -0
- package/src/statistics/sum-array.ts +8 -0
- package/src/statistics/variance.ts +10 -0
- package/styles/globals.css +125 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Divides two numbers
|
|
3
|
+
* @param a - Dividend
|
|
4
|
+
* @param b - Divisor
|
|
5
|
+
* @returns Quotient of a and b
|
|
6
|
+
* @throws Error if b is zero
|
|
7
|
+
*/
|
|
8
|
+
export function divide(a: number, b: number): number {
|
|
9
|
+
if (b === 0) throw new Error("Division by zero")
|
|
10
|
+
return a / b
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to specified decimal places
|
|
3
|
+
* @param value - The number to round
|
|
4
|
+
* @param decimals - Number of decimal places (default: 0)
|
|
5
|
+
* @returns Rounded number
|
|
6
|
+
*/
|
|
7
|
+
export function round(value: number, decimals = 0): number {
|
|
8
|
+
const multiplier = Math.pow(10, decimals)
|
|
9
|
+
return Math.round(value * multiplier) / multiplier
|
|
10
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
add,
|
|
5
|
+
subtract,
|
|
6
|
+
multiply,
|
|
7
|
+
divide,
|
|
8
|
+
modulo,
|
|
9
|
+
percentage,
|
|
10
|
+
clamp,
|
|
11
|
+
round,
|
|
12
|
+
ceil,
|
|
13
|
+
floor,
|
|
14
|
+
factorial,
|
|
15
|
+
fibonacci,
|
|
16
|
+
gcd,
|
|
17
|
+
lcm,
|
|
18
|
+
primeCheck,
|
|
19
|
+
primeList,
|
|
20
|
+
power,
|
|
21
|
+
sqrt,
|
|
22
|
+
cubeRoot,
|
|
23
|
+
mean,
|
|
24
|
+
median,
|
|
25
|
+
mode,
|
|
26
|
+
variance,
|
|
27
|
+
stdDev,
|
|
28
|
+
range,
|
|
29
|
+
randomInt,
|
|
30
|
+
randomFloat,
|
|
31
|
+
randomArray,
|
|
32
|
+
solveLinear,
|
|
33
|
+
solveQuadratic,
|
|
34
|
+
distance,
|
|
35
|
+
slope,
|
|
36
|
+
midpoint,
|
|
37
|
+
triangleArea,
|
|
38
|
+
circleArea,
|
|
39
|
+
degToRad,
|
|
40
|
+
radToDeg,
|
|
41
|
+
kmToMiles,
|
|
42
|
+
milesToKm,
|
|
43
|
+
cToF,
|
|
44
|
+
fToC,
|
|
45
|
+
} from "./index"
|
|
46
|
+
|
|
47
|
+
const args = process.argv.slice(2)
|
|
48
|
+
|
|
49
|
+
function formatOutput(value: any): string {
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return `[${value.map((v) => (typeof v === "number" ? (Number.isInteger(v) ? v : v.toFixed(4)) : v)).join(", ")}]`
|
|
52
|
+
}
|
|
53
|
+
return typeof value === "number" ? (Number.isInteger(value) ? value.toString() : value.toFixed(4)) : String(value)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const commands: { [key: string]: () => void } = {
|
|
57
|
+
add: () => {
|
|
58
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
59
|
+
console.log(formatOutput(add(a, b)))
|
|
60
|
+
},
|
|
61
|
+
subtract: () => {
|
|
62
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
63
|
+
console.log(formatOutput(subtract(a, b)))
|
|
64
|
+
},
|
|
65
|
+
multiply: () => {
|
|
66
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
67
|
+
console.log(formatOutput(multiply(a, b)))
|
|
68
|
+
},
|
|
69
|
+
divide: () => {
|
|
70
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
71
|
+
console.log(formatOutput(divide(a, b)))
|
|
72
|
+
},
|
|
73
|
+
modulo: () => {
|
|
74
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
75
|
+
console.log(formatOutput(modulo(a, b)))
|
|
76
|
+
},
|
|
77
|
+
percentage: () => {
|
|
78
|
+
const [value, percent] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
79
|
+
console.log(formatOutput(percentage(value, percent)))
|
|
80
|
+
},
|
|
81
|
+
clamp: () => {
|
|
82
|
+
const [value, min, max] = [Number.parseFloat(args[1]), Number.parseFloat(args[2]), Number.parseFloat(args[3])]
|
|
83
|
+
console.log(formatOutput(clamp(value, min, max)))
|
|
84
|
+
},
|
|
85
|
+
round: () => {
|
|
86
|
+
const value = Number.parseFloat(args[1])
|
|
87
|
+
const decimals = args[2] ? Number.parseInt(args[2]) : 0
|
|
88
|
+
console.log(formatOutput(round(value, decimals)))
|
|
89
|
+
},
|
|
90
|
+
ceil: () => {
|
|
91
|
+
const value = Number.parseFloat(args[1])
|
|
92
|
+
console.log(formatOutput(ceil(value)))
|
|
93
|
+
},
|
|
94
|
+
floor: () => {
|
|
95
|
+
const value = Number.parseFloat(args[1])
|
|
96
|
+
console.log(formatOutput(floor(value)))
|
|
97
|
+
},
|
|
98
|
+
factorial: () => {
|
|
99
|
+
const n = Number.parseInt(args[1])
|
|
100
|
+
console.log(formatOutput(factorial(n)))
|
|
101
|
+
},
|
|
102
|
+
fibonacci: () => {
|
|
103
|
+
const n = Number.parseInt(args[1])
|
|
104
|
+
console.log(formatOutput(fibonacci(n)))
|
|
105
|
+
},
|
|
106
|
+
gcd: () => {
|
|
107
|
+
const [a, b] = [Number.parseInt(args[1]), Number.parseInt(args[2])]
|
|
108
|
+
console.log(formatOutput(gcd(a, b)))
|
|
109
|
+
},
|
|
110
|
+
lcm: () => {
|
|
111
|
+
const [a, b] = [Number.parseInt(args[1]), Number.parseInt(args[2])]
|
|
112
|
+
console.log(formatOutput(lcm(a, b)))
|
|
113
|
+
},
|
|
114
|
+
primeCheck: () => {
|
|
115
|
+
const n = Number.parseInt(args[1])
|
|
116
|
+
console.log(primeCheck(n))
|
|
117
|
+
},
|
|
118
|
+
primeList: () => {
|
|
119
|
+
const n = Number.parseInt(args[1])
|
|
120
|
+
console.log(formatOutput(primeList(n)))
|
|
121
|
+
},
|
|
122
|
+
power: () => {
|
|
123
|
+
const [base, exp] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
124
|
+
console.log(formatOutput(power(base, exp)))
|
|
125
|
+
},
|
|
126
|
+
sqrt: () => {
|
|
127
|
+
const n = Number.parseFloat(args[1])
|
|
128
|
+
console.log(formatOutput(sqrt(n)))
|
|
129
|
+
},
|
|
130
|
+
cbrt: () => {
|
|
131
|
+
const n = Number.parseFloat(args[1])
|
|
132
|
+
console.log(formatOutput(cubeRoot(n)))
|
|
133
|
+
},
|
|
134
|
+
mean: () => {
|
|
135
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
136
|
+
console.log(formatOutput(mean(nums)))
|
|
137
|
+
},
|
|
138
|
+
median: () => {
|
|
139
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
140
|
+
console.log(formatOutput(median(nums)))
|
|
141
|
+
},
|
|
142
|
+
mode: () => {
|
|
143
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
144
|
+
console.log(formatOutput(mode(nums)))
|
|
145
|
+
},
|
|
146
|
+
variance: () => {
|
|
147
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
148
|
+
console.log(formatOutput(variance(nums)))
|
|
149
|
+
},
|
|
150
|
+
stddev: () => {
|
|
151
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
152
|
+
console.log(formatOutput(stdDev(nums)))
|
|
153
|
+
},
|
|
154
|
+
range: () => {
|
|
155
|
+
const nums = args.slice(1).map(Number.parseFloat)
|
|
156
|
+
console.log(formatOutput(range(nums)))
|
|
157
|
+
},
|
|
158
|
+
randomInt: () => {
|
|
159
|
+
const [min, max] = [Number.parseInt(args[1]), Number.parseInt(args[2])]
|
|
160
|
+
console.log(formatOutput(randomInt(min, max)))
|
|
161
|
+
},
|
|
162
|
+
randomFloat: () => {
|
|
163
|
+
const [min, max] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
164
|
+
console.log(formatOutput(randomFloat(min, max)))
|
|
165
|
+
},
|
|
166
|
+
randomArray: () => {
|
|
167
|
+
const [length, min, max] = [Number.parseInt(args[1]), Number.parseInt(args[2]), Number.parseInt(args[3])]
|
|
168
|
+
console.log(formatOutput(randomArray(length, min, max)))
|
|
169
|
+
},
|
|
170
|
+
solveLinear: () => {
|
|
171
|
+
const [a, b] = [Number.parseFloat(args[1]), Number.parseFloat(args[2])]
|
|
172
|
+
console.log(formatOutput(solveLinear(a, b)))
|
|
173
|
+
},
|
|
174
|
+
solveQuadratic: () => {
|
|
175
|
+
const [a, b, c] = [Number.parseFloat(args[1]), Number.parseFloat(args[2]), Number.parseFloat(args[3])]
|
|
176
|
+
console.log(formatOutput(solveQuadratic(a, b, c)))
|
|
177
|
+
},
|
|
178
|
+
distance: () => {
|
|
179
|
+
const [x1, y1, x2, y2] = [
|
|
180
|
+
Number.parseFloat(args[1]),
|
|
181
|
+
Number.parseFloat(args[2]),
|
|
182
|
+
Number.parseFloat(args[3]),
|
|
183
|
+
Number.parseFloat(args[4]),
|
|
184
|
+
]
|
|
185
|
+
console.log(formatOutput(distance(x1, y1, x2, y2)))
|
|
186
|
+
},
|
|
187
|
+
slope: () => {
|
|
188
|
+
const [x1, y1, x2, y2] = [
|
|
189
|
+
Number.parseFloat(args[1]),
|
|
190
|
+
Number.parseFloat(args[2]),
|
|
191
|
+
Number.parseFloat(args[3]),
|
|
192
|
+
Number.parseFloat(args[4]),
|
|
193
|
+
]
|
|
194
|
+
console.log(formatOutput(slope(x1, y1, x2, y2)))
|
|
195
|
+
},
|
|
196
|
+
midpoint: () => {
|
|
197
|
+
const [x1, y1, x2, y2] = [
|
|
198
|
+
Number.parseFloat(args[1]),
|
|
199
|
+
Number.parseFloat(args[2]),
|
|
200
|
+
Number.parseFloat(args[3]),
|
|
201
|
+
Number.parseFloat(args[4]),
|
|
202
|
+
]
|
|
203
|
+
console.log(formatOutput(midpoint(x1, y1, x2, y2)))
|
|
204
|
+
},
|
|
205
|
+
triangleArea: () => {
|
|
206
|
+
const [a, b, c] = [Number.parseFloat(args[1]), Number.parseFloat(args[2]), Number.parseFloat(args[3])]
|
|
207
|
+
console.log(formatOutput(triangleArea(a, b, c)))
|
|
208
|
+
},
|
|
209
|
+
circleArea: () => {
|
|
210
|
+
const r = Number.parseFloat(args[1])
|
|
211
|
+
console.log(formatOutput(circleArea(r)))
|
|
212
|
+
},
|
|
213
|
+
degToRad: () => {
|
|
214
|
+
const degrees = Number.parseFloat(args[1])
|
|
215
|
+
console.log(formatOutput(degToRad(degrees)))
|
|
216
|
+
},
|
|
217
|
+
radToDeg: () => {
|
|
218
|
+
const radians = Number.parseFloat(args[1])
|
|
219
|
+
console.log(formatOutput(radToDeg(radians)))
|
|
220
|
+
},
|
|
221
|
+
kmToMiles: () => {
|
|
222
|
+
const km = Number.parseFloat(args[1])
|
|
223
|
+
console.log(formatOutput(kmToMiles(km)))
|
|
224
|
+
},
|
|
225
|
+
milesToKm: () => {
|
|
226
|
+
const miles = Number.parseFloat(args[1])
|
|
227
|
+
console.log(formatOutput(milesToKm(miles)))
|
|
228
|
+
},
|
|
229
|
+
cToF: () => {
|
|
230
|
+
const celsius = Number.parseFloat(args[1])
|
|
231
|
+
console.log(formatOutput(cToF(celsius)))
|
|
232
|
+
},
|
|
233
|
+
fToC: () => {
|
|
234
|
+
const fahrenheit = Number.parseFloat(args[1])
|
|
235
|
+
console.log(formatOutput(fToC(fahrenheit)))
|
|
236
|
+
},
|
|
237
|
+
help: () => {
|
|
238
|
+
console.log(`
|
|
239
|
+
math-ops - A comprehensive mathematics utility CLI
|
|
240
|
+
|
|
241
|
+
Usage: math-ops <command> [arguments]
|
|
242
|
+
|
|
243
|
+
Arithmetic Commands:
|
|
244
|
+
add <a> <b> - Add two numbers
|
|
245
|
+
subtract <a> <b> - Subtract two numbers
|
|
246
|
+
multiply <a> <b> - Multiply two numbers
|
|
247
|
+
divide <a> <b> - Divide two numbers
|
|
248
|
+
modulo <a> <b> - Get remainder
|
|
249
|
+
percentage <value> <pct> - Calculate percentage
|
|
250
|
+
clamp <val> <min> <max> - Clamp value between min and max
|
|
251
|
+
round <value> [decimals] - Round to decimal places
|
|
252
|
+
ceil <value> - Round up
|
|
253
|
+
floor <value> - Round down
|
|
254
|
+
|
|
255
|
+
Advanced Commands:
|
|
256
|
+
factorial <n> - Calculate factorial
|
|
257
|
+
fibonacci <n> - Get nth Fibonacci number
|
|
258
|
+
gcd <a> <b> - Greatest common divisor
|
|
259
|
+
lcm <a> <b> - Least common multiple
|
|
260
|
+
primeCheck <n> - Check if number is prime
|
|
261
|
+
primeList <n> - List all primes up to n
|
|
262
|
+
power <base> <exp> - Raise to power
|
|
263
|
+
sqrt <n> - Square root
|
|
264
|
+
cbrt <n> - Cube root
|
|
265
|
+
|
|
266
|
+
Statistics Commands:
|
|
267
|
+
mean <n1> <n2> ... - Calculate mean
|
|
268
|
+
median <n1> <n2> ... - Calculate median
|
|
269
|
+
mode <n1> <n2> ... - Calculate mode
|
|
270
|
+
variance <n1> <n2> ... - Calculate variance
|
|
271
|
+
stddev <n1> <n2> ... - Calculate standard deviation
|
|
272
|
+
range <n1> <n2> ... - Calculate range
|
|
273
|
+
|
|
274
|
+
Random Commands:
|
|
275
|
+
randomInt <min> <max> - Random integer between min and max
|
|
276
|
+
randomFloat <min> <max> - Random float between min and max
|
|
277
|
+
randomArray <len> <min> <max> - Generate random array
|
|
278
|
+
|
|
279
|
+
Algebra Commands:
|
|
280
|
+
solveLinear <a> <b> - Solve ax + b = 0
|
|
281
|
+
solveQuadratic <a> <b> <c> - Solve ax^2 + bx + c = 0
|
|
282
|
+
distance <x1> <y1> <x2> <y2> - Distance between points
|
|
283
|
+
slope <x1> <y1> <x2> <y2> - Slope between points
|
|
284
|
+
midpoint <x1> <y1> <x2> <y2> - Midpoint between points
|
|
285
|
+
triangleArea <a> <b> <c> - Triangle area (Heron's formula)
|
|
286
|
+
circleArea <r> - Circle area
|
|
287
|
+
|
|
288
|
+
Conversion Commands:
|
|
289
|
+
degToRad <degrees> - Degrees to radians
|
|
290
|
+
radToDeg <radians> - Radians to degrees
|
|
291
|
+
kmToMiles <km> - Kilometers to miles
|
|
292
|
+
milesToKm <miles> - Miles to kilometers
|
|
293
|
+
cToF <celsius> - Celsius to Fahrenheit
|
|
294
|
+
fToC <fahrenheit> - Fahrenheit to Celsius
|
|
295
|
+
|
|
296
|
+
Examples:
|
|
297
|
+
math-ops add 10 20
|
|
298
|
+
math-ops factorial 5
|
|
299
|
+
math-ops primeCheck 17
|
|
300
|
+
math-ops solveQuadratic 1 -3 2
|
|
301
|
+
math-ops mean 10 20 30 40 50
|
|
302
|
+
`)
|
|
303
|
+
},
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const command = args[0]
|
|
307
|
+
|
|
308
|
+
if (!command || command === "help") {
|
|
309
|
+
commands.help?.()
|
|
310
|
+
} else if (commands[command]) {
|
|
311
|
+
try {
|
|
312
|
+
commands[command]()
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`)
|
|
315
|
+
process.exit(1)
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
console.error(`Unknown command: ${command}`)
|
|
319
|
+
console.log("Run 'math-ops help' for usage information")
|
|
320
|
+
process.exit(1)
|
|
321
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export * from "./arithmetic/add"
|
|
2
|
+
export * from "./arithmetic/subtract"
|
|
3
|
+
export * from "./arithmetic/multiply"
|
|
4
|
+
export * from "./arithmetic/divide"
|
|
5
|
+
export * from "./arithmetic/modulo"
|
|
6
|
+
export * from "./arithmetic/percentage"
|
|
7
|
+
export * from "./arithmetic/clamp"
|
|
8
|
+
export * from "./arithmetic/round"
|
|
9
|
+
export * from "./arithmetic/ceil"
|
|
10
|
+
export * from "./arithmetic/floor"
|
|
11
|
+
|
|
12
|
+
export * from "./advanced/factorial"
|
|
13
|
+
export * from "./advanced/fibonacci"
|
|
14
|
+
export * from "./advanced/gcd"
|
|
15
|
+
export * from "./advanced/lcm"
|
|
16
|
+
export * from "./advanced/prime-check"
|
|
17
|
+
export * from "./advanced/prime-list"
|
|
18
|
+
export * from "./advanced/power"
|
|
19
|
+
export * from "./advanced/sqrt"
|
|
20
|
+
export * from "./advanced/cube-root"
|
|
21
|
+
|
|
22
|
+
export * from "./statistics/mean"
|
|
23
|
+
export * from "./statistics/median"
|
|
24
|
+
export * from "./statistics/mode"
|
|
25
|
+
export * from "./statistics/variance"
|
|
26
|
+
export * from "./statistics/std-dev"
|
|
27
|
+
export * from "./statistics/range"
|
|
28
|
+
export * from "./statistics/sum-array"
|
|
29
|
+
export * from "./statistics/product-array"
|
|
30
|
+
|
|
31
|
+
export * from "./random/random-int"
|
|
32
|
+
export * from "./random/random-float"
|
|
33
|
+
export * from "./random/random-from-array"
|
|
34
|
+
export * from "./random/random-array"
|
|
35
|
+
|
|
36
|
+
export * from "./algebra/solve-linear"
|
|
37
|
+
export * from "./algebra/solve-quadratic"
|
|
38
|
+
export * from "./algebra/distance"
|
|
39
|
+
export * from "./algebra/slope"
|
|
40
|
+
export * from "./algebra/midpoint"
|
|
41
|
+
export * from "./algebra/triangle-area"
|
|
42
|
+
export * from "./algebra/circle-area"
|
|
43
|
+
|
|
44
|
+
export * from "./convert/deg-to-rad"
|
|
45
|
+
export * from "./convert/rad-to-deg"
|
|
46
|
+
export * from "./convert/km-to-miles"
|
|
47
|
+
export * from "./convert/miles-to-km"
|
|
48
|
+
export * from "./convert/c-to-f"
|
|
49
|
+
export * from "./convert/f-to-c"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates array of random integers
|
|
3
|
+
* @param length - Length of array
|
|
4
|
+
* @param min - Minimum value
|
|
5
|
+
* @param max - Maximum value
|
|
6
|
+
* @returns Array of random numbers
|
|
7
|
+
*/
|
|
8
|
+
export function randomArray(length: number, min: number, max: number): number[] {
|
|
9
|
+
return Array.from({ length }, () => Math.floor(Math.random() * (max - min + 1)) + min)
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates random integer between min and max
|
|
3
|
+
* @param min - Minimum value (inclusive)
|
|
4
|
+
* @param max - Maximum value (inclusive)
|
|
5
|
+
* @returns Random integer
|
|
6
|
+
*/
|
|
7
|
+
export function randomInt(min: number, max: number): number {
|
|
8
|
+
return Math.floor(Math.random() * (max - min + 1)) + min
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates mean (average)
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Mean value
|
|
5
|
+
*/
|
|
6
|
+
export function mean(numbers: number[]): number {
|
|
7
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
8
|
+
return numbers.reduce((a, b) => a + b, 0) / numbers.length
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates median
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Median value
|
|
5
|
+
*/
|
|
6
|
+
export function median(numbers: number[]): number {
|
|
7
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
8
|
+
const sorted = [...numbers].sort((a, b) => a - b)
|
|
9
|
+
const mid = Math.floor(sorted.length / 2)
|
|
10
|
+
return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates mode (most frequent value)
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Mode value(s)
|
|
5
|
+
*/
|
|
6
|
+
export function mode(numbers: number[]): number[] {
|
|
7
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
8
|
+
const freq = new Map<number, number>()
|
|
9
|
+
for (const num of numbers) {
|
|
10
|
+
freq.set(num, (freq.get(num) || 0) + 1)
|
|
11
|
+
}
|
|
12
|
+
const maxFreq = Math.max(...freq.values())
|
|
13
|
+
return Array.from(freq.entries())
|
|
14
|
+
.filter(([, f]) => f === maxFreq)
|
|
15
|
+
.map(([n]) => n)
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates range (max - min)
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Range value
|
|
5
|
+
*/
|
|
6
|
+
export function range(numbers: number[]): number {
|
|
7
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
8
|
+
return Math.max(...numbers) - Math.min(...numbers)
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates standard deviation
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Standard deviation
|
|
5
|
+
*/
|
|
6
|
+
export function stdDev(numbers: number[]): number {
|
|
7
|
+
return Math.sqrt(variance(numbers))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function variance(numbers: number[]): number {
|
|
11
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
12
|
+
const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length
|
|
13
|
+
return numbers.reduce((sum, n) => sum + Math.pow(n - avg, 2), 0) / numbers.length
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates variance
|
|
3
|
+
* @param numbers - Array of numbers
|
|
4
|
+
* @returns Variance value
|
|
5
|
+
*/
|
|
6
|
+
export function variance(numbers: number[]): number {
|
|
7
|
+
if (numbers.length === 0) throw new Error("Array cannot be empty")
|
|
8
|
+
const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length
|
|
9
|
+
return numbers.reduce((sum, n) => sum + Math.pow(n - avg, 2), 0) / numbers.length
|
|
10
|
+
}
|