项目作者: princess-rosella

项目描述 :
JavaScript Integer Math
高级语言: TypeScript
项目地址: git://github.com/princess-rosella/spu-integer-math.git
创建时间: 2018-09-07T21:36:57Z
项目社区:https://github.com/princess-rosella/spu-integer-math

开源协议:MIT License

下载


JavaScript Integer Math

This project implements, in pure JavaScript, a way to perform integer maths with datatypes not natively available in that language.

Typescript Example

  1. import { UInt8 } from "js-integer-math";
  2. UInt8.add(255, 1) === 0
  3. UInt16.add(65535, 1) === 0

Classes

Int8

  1. export declare class Int8 {
  2. static add(a: i8, b: i8): i8;
  3. static sub(a: i8, b: i8): i8;
  4. static mul(a: i8, b: i8): i8;
  5. static div(a: i8, b: i8): i8;
  6. static mod(a: i8, b: i8): i8;
  7. static fromNumber(v: number): i8;
  8. static clamp(value: i8, min: i8, max: i8): i8;
  9. static readonly min: i8;
  10. static readonly max: i8;
  11. static readonly bitWidth: number;
  12. static readonly isSigned: boolean;
  13. }

Int16

  1. export declare class Int16 {
  2. static add(a: i16, b: i16): i16;
  3. static sub(a: i16, b: i16): i16;
  4. static mul(a: i16, b: i16): i16;
  5. static div(a: i16, b: i16): i16;
  6. static mod(a: i16, b: i16): i16;
  7. static fromNumber(v: number): i16;
  8. static clamp(value: i16, min: i16, max: i16): i16;
  9. static readonly min: i16;
  10. static readonly max: i16;
  11. static readonly bitWidth: number;
  12. static readonly isSigned: boolean;
  13. }

Int32

  1. export declare class Int32 {
  2. static add(a: i32, b: i32): i32;
  3. static sub(a: i32, b: i32): i32;
  4. static mul(a: i32, b: i32): i32;
  5. static div(a: i32, b: i32): i32;
  6. static mod(a: i32, b: i32): i32;
  7. static fromNumber(v: number): i32;
  8. static clamp(value: i32, min: i32, max: i32): i32;
  9. static readonly min: i32;
  10. static readonly max: i32;
  11. static readonly bitWidth: number;
  12. static readonly isSigned: boolean;
  13. }

UInt8

  1. export declare class UInt8 {
  2. static add(a: u8, b: u8): u8;
  3. static sub(a: u8, b: u8): u8;
  4. static mul(a: u8, b: u8): u8;
  5. static div(a: u8, b: u8): u8;
  6. static mod(a: u8, b: u8): u8;
  7. static fromNumber(v: number): u8;
  8. static clamp(value: u8, min: u8, max: u8): u8;
  9. static toHex(value: u8): string;
  10. static readonly min: u8;
  11. static readonly max: u8;
  12. static readonly bitWidth: number;
  13. static readonly isSigned: boolean;
  14. }

UInt16

  1. export declare class UInt16 {
  2. static add(a: u16, b: u16): u16;
  3. static sub(a: u16, b: u16): u16;
  4. static mul(a: u16, b: u16): u16;
  5. static div(a: u16, b: u16): u16;
  6. static mod(a: u16, b: u16): u16;
  7. static fromNumber(v: number): u16;
  8. static clamp(value: u16, min: u16, max: u16): u16;
  9. static toHex(value: u16): string;
  10. static readonly min: u16;
  11. static readonly max: u16;
  12. static readonly bitWidth: number;
  13. static readonly isSigned: boolean;
  14. }

UInt32

  1. export declare class UInt32 {
  2. static add(a: u32, b: u32): u32;
  3. static sub(a: u32, b: u32): u32;
  4. static mul(a: u32, b: u32): u32;
  5. static div(a: u32, b: u32): u32;
  6. static mod(a: u32, b: u32): u32;
  7. static fromNumber(v: number): u32;
  8. static clamp(value: u32, min: u32, max: u32): u32;
  9. static toHex(value: u32): string;
  10. static readonly min: u32;
  11. static readonly max: u32;
  12. static readonly bitWidth: number;
  13. static readonly isSigned: boolean;
  14. }

UInt64

  1. export declare class UInt64 {
  2. readonly hi: number;
  3. readonly lo: number;
  4. constructor(lo: number | UInt64, hi?: number);
  5. readonly isZero: boolean;
  6. readonly isNonZero: boolean;
  7. readonly isSafeInteger: boolean;
  8. static add(a: number | UInt64, b: number | UInt64): UInt64;
  9. static sub(a: number | UInt64, b: number | UInt64): UInt64;
  10. static neg(b: number | UInt64): UInt64;
  11. static and(a: number | UInt64, b: number | UInt64): UInt64;
  12. static or(a: number | UInt64, b: number | UInt64): UInt64;
  13. static xor(a: number | UInt64, b: number | UInt64): UInt64;
  14. static not(a: number | UInt64): UInt64;
  15. static shiftLeft(value: number | UInt64, shift: number): UInt64;
  16. static shiftRight(value: number | UInt64, shift: number): UInt64;
  17. static fromNumber(value: number | UInt64): UInt64;
  18. static fromString(value: string, base?: number): UInt64;
  19. static compare(a: number | UInt64, b: number | UInt64): number;
  20. toHex(): string;
  21. toString(): string;
  22. toDebugString(): string;
  23. static toHex(a: number | UInt64): string;
  24. static readonly min: UInt64;
  25. static readonly max: UInt64;
  26. static readonly bitWidth: number;
  27. static readonly isSigned: boolean;
  28. }