Home Reference Source
import Fraction from 'konpeito/src/math/core/Fraction.js'
public class | source

Fraction

Extends:

KonpeitoInteger → Fraction

Fraction class (immutable).

Static Member Summary

Static Public Members
public static get

0.5

public static get

-1

public static get

Negative Infinity.

public static get

Not a Number.

public static get

1

public static get

Positive infinity.

public static get

10

public static get

2

public static get

0

Static Method Summary

Static Public Methods
public static

Create an entity object of this class.

public static

Convert number to Fraction type.

Constructor Summary

Public Constructor
public

Create an fraction.

Member Summary

Public Members
public get

boolean value.

public

denominator

public get

floating point.

public get

integer value.

public

numerator

Method Summary

Public Methods
public

Absolute value.

public

Add.

public

Logical AND.

public

Ceil.

public

Clip number within range.

public

Deep copy.

public

Compare values.

public

Divide.

public

Divide.

public

Equals.

public

Numeric type match.

public

Extended Euclidean algorithm.

public

Factorization.

public

Factorial function, x!.

public

To integer rounded down to the nearest.

public

Floor.

public

Fraction.

public

Euclidean algorithm.

public

Inverse number of this value.

public

Return true if the value is finite number.

public

this === Infinity or -Infinity

public

Return true if the value is integer.

public

this === NaN

public

this < 0

public

this === -Infinity

public

this >= 0

public

this === 1

public

this > 0

public

this === Infinity

public

Return true if the value is prime number.

public

Return true if the value is prime number by Miller-Labin prime number determination method.

public

Return true if the value is repeating decimal.

public

this === 0

public

Least common multiple.

public

Maximum number.

public

Minimum number.

public

Modulo, positive remainder of division.

public

Modular multiplicative inverse.

public

Modular exponentiation.

public

Multiply.

public

Multiply.

public

this * -1

public

Next prime.

public

Logical Not.

public

Logical OR.

public

Power function.

public

Modulo, positive remainder of division.

public

Remainder of division.

public

Rounding to the nearest integer.

public

Multiply a multiple of ten.

public

this << n

  • Calculated as an integer.
public

The positive or negative sign of this number.

public

The positive or negative sign of this number.

public

Square.

public

Subtract.

public

Subtract.

public

return BigDecimal.

public

return BigInteger.

public

return Complex.

public

return Fraction.

public

Convert to string.

public

Convert to JSON.

public

return Matrix.

public

Convert to string.

public

Convert to string.

public

Logical Exclusive-OR.

Inherited Summary

From class KonpeitoInteger
public static get

-1

public static get

Negative Infinity.

public static get

Not a Number.

public static get

1

public static get

Positive infinity.

public static get

10

public static get

2

public static get

0

public static

create(number: any): KonpeitoInteger

Create an entity object of this class.

public static

valueOf(number: any): KonpeitoInteger

Create number.

public get

boolean value.

public get

floating point.

public get

integer value.

public

Absolute value.

public

add(number: any): KonpeitoInteger

Add.

public

and(number: any): KonpeitoInteger

Logical AND.

public

Ceil.

public

Deep copy.

public

compareTo(number: any): number

Compare values.

public

div(number: any): KonpeitoInteger

Divide.

public

divide(number: any): KonpeitoInteger

Divide.

public

equals(number: any): boolean

Equals.

public

extgcd(number: any): KonpeitoInteger[]

Extended Euclidean algorithm.

public

Factorization.

public

Factorial function, x!.

public

To integer rounded down to the nearest.

public

Floor.

public

Fraction.

public

gcd(number: any): KonpeitoInteger

Euclidean algorithm.

public

Inverse number of this value.

public

Return true if the value is finite number.

public

this === Infinity or -Infinity

public

this === NaN

public

this < 0

public

this === -Infinity

public

this >= 0

public

this === 1

public

this > 0

public

this === Infinity

public

Return true if the value is prime number.

public

isProbablePrime(certainty: any): boolean

Return true if the value is prime number by Miller-Labin prime number determination method.

public

this === 0

public

lcm(number: any): KonpeitoInteger

Least common multiple.

public

mod(number: any): KonpeitoInteger

Modulo, positive rem of division.

public

Modular multiplicative inverse.

public

modPow(exponent: any, m: any): KonpeitoInteger

Modular exponentiation.

public

mul(number: any): KonpeitoInteger

Multiply.

public

multiply(number: any): KonpeitoInteger

Multiply.

public

this * -1

public

nextProbablePrime(certainty: any, search_max: any): KonpeitoInteger

Next prime.

public

Logical Not.

public

or(number: any): KonpeitoInteger

Logical OR.

public

pow(exponent: any): KonpeitoInteger

Power function.

public

rem(number: any): KonpeitoInteger

Remainder of division.

public

remainder(number: any): KonpeitoInteger

Remainder of division.

public

Rounding to the nearest integer.

public

Multiply a multiple of ten.

public

this << n

public

sign(): any

The positive or negative sign of this number.

public

signum(): any

The positive or negative sign of this number.

public

Square.

public

sub(number: any): KonpeitoInteger

Subtract.

public

subtract(number: any): KonpeitoInteger

Subtract.

public

return BigDecimal.

public

return BigInteger.

public

return Complex.

public

return Fraction.

public

Convert to JSON.

public

return Matrix.

public

Convert to string.

public

xor(number: any): KonpeitoInteger

Logical Exclusive-OR.

Static Public Members

public static get HALF: Fraction: * source

0.5

Return:

Fraction

0.5

public static get MINUS_ONE: Fraction: * source

-1

Override:

KonpeitoInteger#MINUS_ONE

Return:

Fraction

1

public static get NEGATIVE_INFINITY: Fraction: * source

Negative Infinity.

Override:

KonpeitoInteger#NEGATIVE_INFINITY

Return:

Fraction

Infinity

public static get NaN: Fraction: * source

Not a Number.

Override:

KonpeitoInteger#NaN

Return:

Fraction

NaN

public static get ONE: Fraction: * source

1

Override:

KonpeitoInteger#ONE

Return:

Fraction

1

public static get POSITIVE_INFINITY: Fraction: * source

Positive infinity.

Override:

KonpeitoInteger#POSITIVE_INFINITY

Return:

Fraction

Infinity

public static get TEN: Fraction: * source

10

Override:

KonpeitoInteger#TEN

Return:

Fraction

10

public static get TWO: Fraction: * source

2

Override:

KonpeitoInteger#TWO

Return:

Fraction

2

public static get ZERO: Fraction: * source

0

Override:

KonpeitoInteger#ZERO

Return:

Fraction

0

Static Public Methods

public static create(number: KFractionInputData): Fraction source

Create an entity object of this class.

Override:

KonpeitoInteger#create

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

public static valueOf(number: KFractionInputData): Fraction source

Convert number to Fraction type.

Override:

KonpeitoInteger#valueOf

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

Public Constructors

public constructor(number: KFractionInputData) source

Create an fraction.

Initialization can be performed as follows.

  • 10, "10", "10/1", "10.0/1.0", ["10", "1"], [10, 1]
  • 0.01, "0.01", "0.1e-1", "1/100", [1, 100], [2, 200], ["2", "200"]
  • "1/3", "0.[3]", "0.(3)", "0.'3'", "0."3"", [1, 3], [2, 6]
  • "3.555(123)" = 3.555123123123..., "147982 / 41625"

Override:

KonpeitoInteger#constructor

Params:

NameTypeAttributeDescription
number KFractionInputData
  • optional

Fraction data. See how to use the function.

Public Members

public get booleanValue: boolean: * source

boolean value.

Override:

KonpeitoInteger#booleanValue

Return:

boolean

public denominator: BigInteger source

denominator

public get doubleValue: number: * source

floating point.

Override:

KonpeitoInteger#doubleValue

Return:

number

public get intValue: number: * source

integer value.

Override:

KonpeitoInteger#intValue

Return:

number

public numerator: BigInteger source

numerator

Public Methods

public abs(): Fraction source

Absolute value.

Override:

KonpeitoInteger#abs

Return:

Fraction

abs(A)

public add(num: KFractionInputData): Fraction source

Add.

Override:

KonpeitoInteger#add

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A + B

public and(number: KFractionInputData): Fraction source

Logical AND.

  • Calculated as an integer.

Override:

KonpeitoInteger#and

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A & B

public ceil(): Fraction source

Ceil.

Override:

KonpeitoInteger#ceil

Return:

Fraction

ceil(A)

public clip(min: KFractionInputData, max: KFractionInputData): Fraction source

Clip number within range.

Params:

NameTypeAttributeDescription
min KFractionInputData
max KFractionInputData

Return:

Fraction

min(max(x, min), max)

public clone(): Fraction source

Deep copy.

Override:

KonpeitoInteger#clone

Return:

Fraction

public compareTo(num: KFractionInputData): number source

Compare values.

Override:

KonpeitoInteger#compareTo

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

number

A > B ? 1 : (A === B ? 0 : -1)

public div(num: KFractionInputData): Fraction source

Divide.

Override:

KonpeitoInteger#div

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A / B

public divide(number: KFractionInputData): Fraction source

Divide.

Override:

KonpeitoInteger#divide

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

fix(A / B)

public equals(num: KFractionInputData): boolean source

Equals.

Override:

KonpeitoInteger#equals

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

boolean

A === B

public equalsState(number: KFractionInputData): boolean source

Numeric type match.

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

boolean

public extgcd(number: KFractionInputData): Array<Fraction> source

Extended Euclidean algorithm.

  • Calculated as an integer.

Override:

KonpeitoInteger#extgcd

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Array<Fraction>

[a, b, gcd(x, y)], Result of calculating ax + by = gcd(x, y).

public factor(): Fraction[] source

Factorization.

  • Calculated as an integer.
  • Calculate up to 9007199254740991.

Override:

KonpeitoInteger#factor

Return:

Fraction[]

factor

public factorial(): Fraction source

Factorial function, x!.

  • Supports only integers.

Override:

KonpeitoInteger#factorial

Return:

Fraction

n!

public fix(): Fraction source

To integer rounded down to the nearest.

Override:

KonpeitoInteger#fix

Return:

Fraction

fix(A), trunc(A)

public floor(): Fraction source

Floor.

Override:

KonpeitoInteger#floor

Return:

Fraction

floor(A)

public fract(): Fraction source

Fraction.

Override:

KonpeitoInteger#fract

Return:

Fraction

fract(A)

public gcd(number: KFractionInputData): Fraction source

Euclidean algorithm.

  • Calculated as an integer.

Override:

KonpeitoInteger#gcd

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

gcd(x, y)

public inv(): Fraction source

Inverse number of this value.

Override:

KonpeitoInteger#inv

Return:

Fraction

1 / A

public isFinite(): boolean source

Return true if the value is finite number.

Override:

KonpeitoInteger#isFinite

Return:

boolean

!isNaN(A) && !isInfinite(A)

public isInfinite(): boolean source

this === Infinity or -Infinity

Override:

KonpeitoInteger#isInfinite

Return:

boolean

isPositiveInfinity(A) || isNegativeInfinity(A)

public isInteger(): boolean source

Return true if the value is integer.

Return:

boolean

public isNaN(): boolean source

this === NaN

Override:

KonpeitoInteger#isNaN

Return:

boolean

isNaN(A)

public isNegative(): boolean source

this < 0

Override:

KonpeitoInteger#isNegative

Return:

boolean

public isNegativeInfinity(): boolean source

this === -Infinity

Override:

KonpeitoInteger#isNegativeInfinity

Return:

boolean

isNegativeInfinity(A)

public isNotNegative(): boolean source

this >= 0

Override:

KonpeitoInteger#isNotNegative

Return:

boolean

public isOne(): boolean source

this === 1

Override:

KonpeitoInteger#isOne

Return:

boolean

A === 1

public isPositive(): boolean source

this > 0

Override:

KonpeitoInteger#isPositive

Return:

boolean

public isPositiveInfinity(): boolean source

this === Infinity

Override:

KonpeitoInteger#isPositiveInfinity

Return:

boolean

isPositiveInfinity(A)

public isPrime(): boolean source

Return true if the value is prime number.

  • Calculated as an integer.
  • Calculate up to 9007199254740991.

Override:

KonpeitoInteger#isPrime

Return:

boolean

If the calculation range is exceeded, null is returned.

public isProbablePrime(certainty: KFractionInputData): boolean source

Return true if the value is prime number by Miller-Labin prime number determination method.

Attention : it takes a very long time to process.

  • Calculated as an integer.

Override:

KonpeitoInteger#isProbablePrime

Params:

NameTypeAttributeDescription
certainty KFractionInputData
  • optional
  • default: 100

Repeat count (prime precision).

Return:

boolean

public isRepeatingDecimal(): boolean source

Return true if the value is repeating decimal.

Return:

boolean

public isZero(): boolean source

this === 0

Override:

KonpeitoInteger#isZero

Return:

boolean

A === 0

public lcm(number: KFractionInputData): Fraction source

Least common multiple.

  • Calculated as an integer.

Override:

KonpeitoInteger#lcm

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

lcm(x, y)

public max(number: KFractionInputData): Fraction source

Maximum number.

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

max([A, B])

public min(number: KFractionInputData): Fraction source

Minimum number.

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

min([A, B])

public mod(num: KFractionInputData): Fraction source

Modulo, positive remainder of division.

  • Result has same sign as the Divisor.

Override:

KonpeitoInteger#mod

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A mod B

public modInverse(m: KFractionInputData): Fraction source

Modular multiplicative inverse.

  • Calculated as an integer.

Override:

KonpeitoInteger#modInverse

Params:

NameTypeAttributeDescription
m KFractionInputData

Return:

Fraction

A^(-1) mod m

public modPow(exponent: KFractionInputData, m: KFractionInputData): Fraction source

Modular exponentiation.

  • Calculated as an integer.

Override:

KonpeitoInteger#modPow

Params:

NameTypeAttributeDescription
exponent KFractionInputData
m KFractionInputData

Return:

Fraction

A^B mod m

public mul(num: KFractionInputData): Fraction source

Multiply.

Override:

KonpeitoInteger#mul

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A * B

public multiply(number: KFractionInputData): Fraction source

Multiply.

Override:

KonpeitoInteger#multiply

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A * B

public negate(): Fraction source

this * -1

Override:

KonpeitoInteger#negate

Return:

Fraction

A

public nextProbablePrime(certainty: KFractionInputData, search_max: KFractionInputData): Fraction source

Next prime.

Override:

KonpeitoInteger#nextProbablePrime

Params:

NameTypeAttributeDescription
certainty KFractionInputData
  • optional
  • default: 100

Repeat count (prime precision).

search_max KFractionInputData
  • optional
  • default: 100000

Search range of next prime.

Return:

Fraction

public not(): Fraction source

Logical Not. (mutable)

  • Calculated as an integer.

Override:

KonpeitoInteger#not

Return:

Fraction

!A

public or(number: KFractionInputData): Fraction source

Logical OR.

  • Calculated as an integer.

Override:

KonpeitoInteger#or

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A | B

public pow(num: KFractionInputData): Fraction source

Power function.

  • Supports only integers.

Override:

KonpeitoInteger#pow

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

pow(A, B)

public rem(num: KFractionInputData): Fraction source

Modulo, positive remainder of division.

  • Result has same sign as the Dividend.

Override:

KonpeitoInteger#rem

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A rem B

public remainder(number: KFractionInputData): Fraction source

Remainder of division.

  • Result has same sign as the Dividend.

Override:

KonpeitoInteger#remainder

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A % B

public round(): Fraction source

Rounding to the nearest integer.

Override:

KonpeitoInteger#round

Return:

Fraction

round(A)

public scaleByPowerOfTen(n: KFractionInputData): Fraction source

Multiply a multiple of ten.

  • Supports only integers.

Override:

KonpeitoInteger#scaleByPowerOfTen

Params:

NameTypeAttributeDescription
n KFractionInputData

Return:

Fraction

public shift(n: KFractionInputData): Fraction source

this << n

  • Calculated as an integer.

Override:

KonpeitoInteger#shift

Params:

NameTypeAttributeDescription
n KFractionInputData

Return:

Fraction

A << n

public sign(): number source

The positive or negative sign of this number.

  • +1 if positive, -1 if negative, 0 if 0.

Override:

KonpeitoInteger#sign

Return:

number

public signum(): number source

The positive or negative sign of this number.

  • +1 if positive, -1 if negative, 0 if 0.

Override:

KonpeitoInteger#signum

Return:

number

public square(): Fraction source

Square.

Override:

KonpeitoInteger#square

Return:

Fraction

pow(A, 2)

public sub(num: KFractionInputData): Fraction source

Subtract.

Override:

KonpeitoInteger#sub

Params:

NameTypeAttributeDescription
num KFractionInputData

Return:

Fraction

A - B

public subtract(number: KFractionInputData): Fraction source

Subtract.

Override:

KonpeitoInteger#subtract

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A - B

public toBigDecimal(mc: MathContext): BigDecimal source

return BigDecimal.

Override:

KonpeitoInteger#toBigDecimal

Params:

NameTypeAttributeDescription
mc MathContext
  • optional

MathContext setting after calculation.

Return:

BigDecimal

public toBigInteger(): BigInteger source

return BigInteger.

Override:

KonpeitoInteger#toBigInteger

Return:

BigInteger

public toComplex(): Complex source

return Complex.

Override:

KonpeitoInteger#toComplex

Return:

Complex

public toFraction(): Fraction source

return Fraction.

Override:

KonpeitoInteger#toFraction

Return:

Fraction

public toFractionString(): string source

Convert to string. For example, output 1/3 if 0.333....

Return:

string

public toJSON(): string source

Convert to JSON.

Override:

KonpeitoInteger#toJSON

Return:

string

public toMatrix(): Matrix source

return Matrix.

Override:

KonpeitoInteger#toMatrix

Return:

Matrix

public toPlainString(depth_max: KFractionInputData): string source

Convert to string. For example, output 0.(3) if 0.333....

Params:

NameTypeAttributeDescription
depth_max KFractionInputData
  • optional

Maximum number of divisions.

Return:

string

public toString(): string source

Convert to string.

Override:

KonpeitoInteger#toString

Return:

string

public xor(number: KFractionInputData): Fraction source

Logical Exclusive-OR.

  • Calculated as an integer.

Override:

KonpeitoInteger#xor

Params:

NameTypeAttributeDescription
number KFractionInputData

Return:

Fraction

A ^ B