Link Search Menu Expand Document

Xnumber

xnumber.ts#L12

Class XNumber

Extended Number class.

constructor (num: number, den: number, unit: %|π): XNumber

Name Type Default Description  
num number      
den number      
unit % π    

Property .den

Property .num : number

Property .unit

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 .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 (): string

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 © 2021 Mathigon.org