-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(math): use new function aliases, update deps
- Loading branch information
1 parent
0d9a0de
commit dd0337f
Showing
13 changed files
with
167 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { FnN2 } from "@thi.ng/api"; | ||
import { EPS } from "./api"; | ||
|
||
export const absDiff = (x: number, y: number) => Math.abs(x - y); | ||
export const absDiff: FnN2 = (x, y) => Math.abs(x - y); | ||
|
||
export const sign = (x: number, eps = EPS) => (x > eps ? 1 : x < -eps ? -1 : 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,73 @@ | ||
import type { FnN, FnN2 } from "@thi.ng/api"; | ||
|
||
const M8 = 0xff; | ||
const M16 = 0xffff; | ||
|
||
export const signExtend8 = (a: number) => ((a &= M8), a & 0x80 ? a | ~M8 : a); | ||
|
||
export const signExtend16 = (a: number) => ( | ||
(a &= M16), a & 0x8000 ? a | ~M16 : a | ||
); | ||
export const signExtend8: FnN = (a) => ((a &= M8), a & 0x80 ? a | ~M8 : a); | ||
export const signExtend16: FnN = (a) => ((a &= M16), a & 0x8000 ? a | ~M16 : a); | ||
|
||
export const addi8 = (a: number, b: number) => signExtend8((a | 0) + (b | 0)); | ||
export const divi8 = (a: number, b: number) => signExtend8((a | 0) / (b | 0)); | ||
export const muli8 = (a: number, b: number) => signExtend8((a | 0) * (b | 0)); | ||
export const subi8 = (a: number, b: number) => signExtend8((a | 0) - (b | 0)); | ||
export const andi8 = (a: number, b: number) => signExtend8((a | 0) & (b | 0)); | ||
export const ori8 = (a: number, b: number) => signExtend8(a | 0 | (b | 0)); | ||
export const xori8 = (a: number, b: number) => signExtend8((a | 0) ^ (b | 0)); | ||
export const noti8 = (a: number) => signExtend8(~a); | ||
// prettier-ignore | ||
export const lshifti8 = (a: number, b: number) => signExtend8((a | 0) << (b | 0)); | ||
// prettier-ignore | ||
export const rshifti8 = (a: number, b: number) => signExtend8((a | 0) >> (b | 0)); | ||
export const addi8: FnN2 = (a, b) => signExtend8((a | 0) + (b | 0)); | ||
export const divi8: FnN2 = (a, b) => signExtend8((a | 0) / (b | 0)); | ||
export const muli8: FnN2 = (a, b) => signExtend8((a | 0) * (b | 0)); | ||
export const subi8: FnN2 = (a, b) => signExtend8((a | 0) - (b | 0)); | ||
export const andi8: FnN2 = (a, b) => signExtend8((a | 0) & (b | 0)); | ||
export const ori8: FnN2 = (a, b) => signExtend8(a | 0 | (b | 0)); | ||
export const xori8: FnN2 = (a, b) => signExtend8((a | 0) ^ (b | 0)); | ||
export const noti8: FnN = (a) => signExtend8(~a); | ||
export const lshifti8: FnN2 = (a, b) => signExtend8((a | 0) << (b | 0)); | ||
export const rshifti8: FnN2 = (a, b) => signExtend8((a | 0) >> (b | 0)); | ||
|
||
export const addi16 = (a: number, b: number) => signExtend16((a | 0) + (b | 0)); | ||
export const divi16 = (a: number, b: number) => signExtend16((a | 0) / (b | 0)); | ||
export const muli16 = (a: number, b: number) => signExtend16((a | 0) * (b | 0)); | ||
export const subi16 = (a: number, b: number) => signExtend16((a | 0) - (b | 0)); | ||
export const andi16 = (a: number, b: number) => signExtend16((a | 0) & (b | 0)); | ||
export const ori16 = (a: number, b: number) => signExtend16(a | 0 | (b | 0)); | ||
export const xori16 = (a: number, b: number) => signExtend16((a | 0) ^ (b | 0)); | ||
export const noti16 = (a: number) => signExtend16(~a); | ||
// prettier-ignore | ||
export const lshifti16 = (a: number, b: number) => signExtend16((a | 0) << (b | 0)); | ||
// prettier-ignore | ||
export const rshifti16 = (a: number, b: number) => signExtend16((a | 0) >> (b | 0)); | ||
export const addi16: FnN2 = (a, b) => signExtend16((a | 0) + (b | 0)); | ||
export const divi16: FnN2 = (a, b) => signExtend16((a | 0) / (b | 0)); | ||
export const muli16: FnN2 = (a, b) => signExtend16((a | 0) * (b | 0)); | ||
export const subi16: FnN2 = (a, b) => signExtend16((a | 0) - (b | 0)); | ||
export const andi16: FnN2 = (a, b) => signExtend16((a | 0) & (b | 0)); | ||
export const ori16: FnN2 = (a, b) => signExtend16(a | 0 | (b | 0)); | ||
export const xori16: FnN2 = (a, b) => signExtend16((a | 0) ^ (b | 0)); | ||
export const noti16: FnN = (a) => signExtend16(~a); | ||
export const lshifti16: FnN2 = (a, b) => signExtend16((a | 0) << (b | 0)); | ||
export const rshifti16: FnN2 = (a, b) => signExtend16((a | 0) >> (b | 0)); | ||
|
||
export const addi32 = (a: number, b: number) => ((a | 0) + (b | 0)) | 0; | ||
export const divi32 = (a: number, b: number) => ((a | 0) / (b | 0)) | 0; | ||
export const muli32 = (a: number, b: number) => ((a | 0) * (b | 0)) | 0; | ||
export const subi32 = (a: number, b: number) => ((a | 0) - (b | 0)) | 0; | ||
export const andi32 = (a: number, b: number) => (a | 0) & (b | 0); | ||
export const ori32 = (a: number, b: number) => a | 0 | (b | 0); | ||
export const xori32 = (a: number, b: number) => (a | 0) ^ (b | 0); | ||
export const lshifti32 = (a: number, b: number) => (a | 0) << (b | 0); | ||
export const rshifti32 = (a: number, b: number) => (a | 0) >> (b | 0); | ||
export const noti32 = (a: number) => ~a; | ||
export const addi32: FnN2 = (a, b) => ((a | 0) + (b | 0)) | 0; | ||
export const divi32: FnN2 = (a, b) => ((a | 0) / (b | 0)) | 0; | ||
export const muli32: FnN2 = (a, b) => ((a | 0) * (b | 0)) | 0; | ||
export const subi32: FnN2 = (a, b) => ((a | 0) - (b | 0)) | 0; | ||
export const andi32: FnN2 = (a, b) => (a | 0) & (b | 0); | ||
export const ori32: FnN2 = (a, b) => a | 0 | (b | 0); | ||
export const xori32: FnN2 = (a, b) => (a | 0) ^ (b | 0); | ||
export const lshifti32: FnN2 = (a, b) => (a | 0) << (b | 0); | ||
export const rshifti32: FnN2 = (a, b) => (a | 0) >> (b | 0); | ||
export const noti32: FnN = (a) => ~a; | ||
|
||
// prettier-ignore | ||
export const addu8 = (a: number, b: number) => ((a & M8) + (b & M8)) & M8; | ||
// prettier-ignore | ||
export const divu8 = (a: number, b: number) => ((a & M8) / (b & M8)) & M8; | ||
// prettier-ignore | ||
export const mulu8 = (a: number, b: number) => ((a & M8) * (b & M8)) & M8; | ||
// prettier-ignore | ||
export const subu8 = (a: number, b: number) => ((a & M8) - (b & M8)) & M8; | ||
// prettier-ignore | ||
export const andu8 = (a: number, b: number) => ((a & M8) & (b & M8)) & M8; | ||
// prettier-ignore | ||
export const oru8 = (a: number, b: number) => ((a & M8) | (b & M8)) & M8; | ||
// prettier-ignore | ||
export const xoru8 = (a: number, b: number) => ((a & M8) ^ (b & M8)) & M8; | ||
export const notu8 = (a: number) => ~a & M8; | ||
export const lshiftu8 = (a: number, b: number) => ((a & M8) << (b & M8)) & M8; | ||
export const rshiftu8 = (a: number, b: number) => ((a & M8) >>> (b & M8)) & M8; | ||
export const addu8: FnN2 = (a, b) => ((a & M8) + (b & M8)) & M8; | ||
export const divu8: FnN2 = (a, b) => ((a & M8) / (b & M8)) & M8; | ||
export const mulu8: FnN2 = (a, b) => ((a & M8) * (b & M8)) & M8; | ||
export const subu8: FnN2 = (a, b) => ((a & M8) - (b & M8)) & M8; | ||
export const andu8: FnN2 = (a, b) => a & M8 & (b & M8) & M8; | ||
export const oru8: FnN2 = (a, b) => ((a & M8) | (b & M8)) & M8; | ||
export const xoru8: FnN2 = (a, b) => ((a & M8) ^ (b & M8)) & M8; | ||
export const notu8: FnN = (a) => ~a & M8; | ||
export const lshiftu8: FnN2 = (a, b) => ((a & M8) << (b & M8)) & M8; | ||
export const rshiftu8: FnN2 = (a, b) => ((a & M8) >>> (b & M8)) & M8; | ||
|
||
// prettier-ignore | ||
export const addu16 = (a: number, b: number) => ((a & M16) + (b & M16)) & M16; | ||
// prettier-ignore | ||
export const divu16 = (a: number, b: number) => ((a & M16) / (b & M16)) & M16; | ||
// prettier-ignore | ||
export const mulu16 = (a: number, b: number) => ((a & M16) * (b & M16)) & M16; | ||
// prettier-ignore | ||
export const subu16 = (a: number, b: number) => ((a & M16) - (b & M16)) & M16; | ||
// prettier-ignore | ||
export const andu16 = (a: number, b: number) => ((a & M16) & (b & M16)) & M16; | ||
// prettier-ignore | ||
export const oru16 = (a: number, b: number) => ((a & M16) | (b & M16)) & M16; | ||
// prettier-ignore | ||
export const xoru16 = (a: number, b: number) => ((a & M16) ^ (b & M16)) & M16; | ||
export const notu16 = (a: number) => ~a & M16; | ||
// prettier-ignore | ||
export const lshiftu16 = (a: number, b: number) => ((a & M16) << (b & M16)) & M16; | ||
// prettier-ignore | ||
export const rshiftu16 = (a: number, b: number) => ((a & M16) >>> (b & M16)) & M16; | ||
export const addu16: FnN2 = (a, b) => ((a & M16) + (b & M16)) & M16; | ||
export const divu16: FnN2 = (a, b) => ((a & M16) / (b & M16)) & M16; | ||
export const mulu16: FnN2 = (a, b) => ((a & M16) * (b & M16)) & M16; | ||
export const subu16: FnN2 = (a, b) => ((a & M16) - (b & M16)) & M16; | ||
export const andu16: FnN2 = (a, b) => a & M16 & (b & M16) & M16; | ||
export const oru16: FnN2 = (a, b) => ((a & M16) | (b & M16)) & M16; | ||
export const xoru16: FnN2 = (a, b) => ((a & M16) ^ (b & M16)) & M16; | ||
export const notu16: FnN = (a) => ~a & M16; | ||
export const lshiftu16: FnN2 = (a, b) => ((a & M16) << (b & M16)) & M16; | ||
export const rshiftu16: FnN2 = (a, b) => ((a & M16) >>> (b & M16)) & M16; | ||
|
||
export const addu32 = (a: number, b: number) => ((a >>> 0) + (b >>> 0)) >>> 0; | ||
export const divu32 = (a: number, b: number) => ((a >>> 0) / (b >>> 0)) >>> 0; | ||
export const mulu32 = (a: number, b: number) => ((a >>> 0) * (b >>> 0)) >>> 0; | ||
export const subu32 = (a: number, b: number) => ((a >>> 0) - (b >>> 0)) >>> 0; | ||
export const andu32 = (a: number, b: number) => ((a >>> 0) & (b >>> 0)) >>> 0; | ||
export const oru32 = (a: number, b: number) => ((a >>> 0) | (b >>> 0)) >>> 0; | ||
export const xoru32 = (a: number, b: number) => ((a >>> 0) ^ (b >>> 0)) >>> 0; | ||
export const notu32 = (a: number) => ~a >>> 0; | ||
// prettier-ignore | ||
export const lshiftu32 = (a: number, b: number) => ((a >>> 0) << (b >>> 0)) >>> 0; | ||
// prettier-ignore | ||
export const rshiftu32 = (a: number, b: number) => ((a >>> 0) >>> (b >>> 0)) >>> 0; | ||
export const addu32: FnN2 = (a, b) => ((a >>> 0) + (b >>> 0)) >>> 0; | ||
export const divu32: FnN2 = (a, b) => ((a >>> 0) / (b >>> 0)) >>> 0; | ||
export const mulu32: FnN2 = (a, b) => ((a >>> 0) * (b >>> 0)) >>> 0; | ||
export const subu32: FnN2 = (a, b) => ((a >>> 0) - (b >>> 0)) >>> 0; | ||
export const andu32: FnN2 = (a, b) => ((a >>> 0) & (b >>> 0)) >>> 0; | ||
export const oru32: FnN2 = (a, b) => ((a >>> 0) | (b >>> 0)) >>> 0; | ||
export const xoru32: FnN2 = (a, b) => ((a >>> 0) ^ (b >>> 0)) >>> 0; | ||
export const notu32: FnN = (a) => ~a >>> 0; | ||
export const lshiftu32: FnN2 = (a, b) => ((a >>> 0) << (b >>> 0)) >>> 0; | ||
export const rshiftu32: FnN2 = (a, b) => ((a >>> 0) >>> (b >>> 0)) >>> 0; |
Oops, something went wrong.