@jlhv/numeric-helper
Version:
A simple utility library for numeric manipulation.
45 lines (44 loc) • 2.44 kB
TypeScript
/**
* Numeric Helper Library
* Provides utility functions for numeric manipulation.
*/
/** Checks if a number is even. */
export declare function isEven(num: number): boolean;
/** Checks if a number is odd. */
export declare function isOdd(num: number): boolean;
/** Checks if a number is prime (without using Math.sqrt). */
export declare function isPrime(num: number): boolean;
/** Calculates the factorial of a number (non-recursive). */
export declare function factorial(num: number): number;
/** Returns the nth Fibonacci number (without recursion). */
export declare function fibonacci(n: number): number;
/** Returns the sum of an array of numbers. */
export declare function sum(arr: number[]): number;
/** Returns the average of an array of numbers. */
export declare function average(arr: number[]): number;
/** Finds the greatest common divisor (GCD) without using modulo. */
export declare function gcd(a: number, b: number): number;
/** Finds the least common multiple (LCM) using GCD. */
export declare function lcm(a: number, b: number): number;
/** Restricts a number between a min and max value. */
export declare function clamp(num: number, min: number, max: number): number;
/** Converts a number to binary (without built-in functions). */
export declare function toBinary(num: number): string;
/** Converts a number to hexadecimal (without built-in functions). */
export declare function toHex(num: number): string;
/** Generates a random integer between min and max (without Math.random). */
export declare function randomInt(min: number, max: number): number;
/** Checks if a value is numeric. */
export declare function isNumeric(value: any): boolean;
/** Converts degrees to radians (without using Math.PI). */
export declare function degToRad(degrees: number): number;
/** Converts radians to degrees (without using Math.PI). */
export declare function radToDeg(radians: number): number;
/** Computes the power of a number (base^exp) without using Math.pow. */
export declare function power(base: number, exp: number): number;
/** Computes the square root of a number using the Babylonian method. */
export declare function sqrt(num: number): number;
/** Computes the nth root of a number using Newton's method. */
export declare function nthRoot(num: number, n: number): number;
/** Checks if a number is a perfect square (without Math.sqrt). */
export declare function isPerfectSquare(num: number): boolean;