Xnumber

Class XNumber

Extended Number class.

constructor (num: number, den: number, unit: Suffix): XNumber

Name Type Default Description
num number    
den number    
unit Suffix    

Property .den

Property .num : number

Property .unit ?: Suffix

Accessor .inverse : XNumber

Returns 1/x of this number.

Accessor .negative : XNumber

Returns -x of this number.

Accessor .sign : number

Accessor .simplified : XNumber

Simplifies fractions, e.g. 4/8 would become 1/2.

Accessor .value : number

Returns the value of this number as a decimal. For example, 2/5 and 40% would both return 0.4.

Method .add (a: number|XNumber): XNumber

Name Type Default Description  
a number XNumber    

Method .clamp (min: number, max: number): XNumber

Name Type Default Description
min number    
max number    

Method .divide (a: number|XNumber): XNumber

Name Type Default Description  
a number XNumber    

Method .multiply (a: number|XNumber): XNumber

Name Type Default Description  
a number XNumber    

Method .subtract (a: number|XNumber): XNumber

Name Type Default Description  
a number XNumber    

Method .toMathML (): string

Method .toString (precision: number): string

Name Type Default Description
precision number 4  

Method .valueOf (): number

static Method .difference (a: XNumber, b: number|XNumber): XNumber

Calculates the difference of two numbers a and b.

Name Type Default Description  
a XNumber      
b number XNumber    

static Method .fractionFromDecimal (x: number, maxDen: number): XNumber

Converts a decimal into the closest fraction with a given maximum denominator.

Name Type Default Description
x number    
maxDen number 100  

static Method .fromString (s: string): undefined|XNumber

Parses a number string, e.g. ‘1/2’ or ‘20.7%’.

Name Type Default Description
s string    

static Method .product (a: XNumber, b: number|XNumber): XNumber

Calculates the product of two numbers a and b.

Name Type Default Description  
a XNumber      
b number XNumber    

static Method .quotient (a: XNumber, b: number|XNumber): XNumber

Calculates the quotient of two fractions a and b.

Name Type Default Description  
a XNumber      
b number XNumber    

static Method .sum (a: XNumber, b: number|XNumber): XNumber

Calculates the sum of two fractions a and b.

Name Type Default Description  
a XNumber      
b number XNumber    

Copyright © 2024 Mathigon.org