//================================================================ /** * @packageDocumentation * @module std */ //================================================================ import { INegatable } from "./INegatable"; import { IComputable } from "./IComputable"; type PlusParam = number | string | Pick, "plus">; type Param> = | number | Pick, Key>; /* --------------------------------------------------------- PLUS --------------------------------------------------------- */ export function plus, Y = X, Ret = X>( x: X, y: Y, ): Ret { if ((x as Partial>).plus instanceof Function) return (x as Partial>).plus!(y); else return x + y; } export function minus, Y = X, Ret = X>( x: X, y: Y, ): Ret { if ((x as Partial>).minus instanceof Function) return (x as Partial>).minus!(y); else return (x - y) as any; } export function negate, Ret = X>(x: X): Ret { if ((x as INegatable).negate instanceof Function) return (x as INegatable).negate(); else return -x; } /* --------------------------------------------------------- MULTIPLY --------------------------------------------------------- */ export function multiplies< X extends Param, Y = X, Ret = X, >(x: X, y: Y): Ret { if ((x as Partial>).multiplies instanceof Function) return (x as Partial>).multiplies!(y); else return (x * y); } export function divides, Y = X, Ret = X>( x: X, y: Y, ): Ret { if ((x as Partial>).divides instanceof Function) return (x as Partial>).divides!(y); else return (x / y); } export function modules, Y = X, Ret = X>( x: X, y: Y, ): Ret { if ((x as Partial>).modules instanceof Function) return (x as Partial>).modules!(y); else return (x % y); }