Library "fraction" Fraction Creation and Basic Operations. Cracked a tough problem in making this Polarity Agnostic Decimal without a cheating "abs * sign of input".
it's quite fast, however still test for errors before production use. >> Big Neon Sign on 1/0 value. <<
Int Array (LOC 0/1)..
To/From Decimal(float)
Comparison ( < / == / >)
Add / Sub / Mult / Div
Invert polarity +/-
String output with 2 formats ..
make(_numerator, _denominator, _val) Parameters: _numerator: (int) above the line integer ie: ____ of (___ / bottom ) _denominator: (int) below the line integer ie: ____ of (top / ______ ) _val: (int) OPTIONAL (for no real reason including it) integer to multiply Returns: array<int> where index 0 is Numerator, 1 is Denominator
add(_fraction, _fraction2) Perform add operation (left adds right onto ) Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: array<int> where index 0 is Numerator, 1 is Denominator
subtract(_fraction, _fraction2) Perform subtract operation (left subtracts right from ) Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: array<int> where index 0 is Numerator, 1 is Denominator
multiply(_fraction, _fraction2) Perform multiply operation (left multiplies by right ) Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: array<int> where index 0 is Numerator, 1 is Denominator
divide(_fraction, _fraction2) Perform divide operation (left divides by right ) Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: array<int> where index 0 is Numerator, 1 is Denominator
negative(_fraction) Perform Negative number inversion ie: (-1/2 => 1/2) or (3/5 => -3/5) Parameters: _fraction: (array<int>) Fraction Object to invert to/from negative Returns: array<int> where index 0 is Numerator, 1 is Denominator
isSmaller(_fraction, _fraction2) Check if first fraction is smaller Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: True if smaller, false if bigger
isLarger(_fraction, _fraction2) Check if first fraction is larger Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: True if smaller, false if bigger
isEqual(_fraction, _fraction2) Check if first fraction is equal Parameters: _fraction: (array<int>) left side Fraction Object _fraction2: (array<int>) right side Fraction Object Returns: True if smaller, false if bigger
fromDec(_input, _epsilon, _iterations) Convert Decimal to Fraction array note : this is my own Negative Number Capable (tiny speed loss) adaptation of the fastest algo out there Exclusive for Tradingview. Parameters: _input: (float) Decimal Input _epsilon: (int) (OPTIONAL) to precision 0's after dec 0.0000 -> epsilon 0's _iterations: (int) (OPTIONAL) Maximum iterations Till give up Returns: array<int> where index 0 is Numerator, 1 is Denominator
toDec() Convert Fraction to Decimal Output Returns: Float of fration
toString(_fraction) Create "A/B" or "A and B/C" String Value of Fraction. Parameters: _fraction: (array<int>) Fraction Object to invert to/from negative Returns: String as (-)? A and B/C format
진정한 TradingView 정신에 따라, 저자는 이 파인 코드를 다른 파인 프로그래머들이 재사용할 수 있도록 오픈 소스 라이브러리로 공개했습니다. 저자에게 박수를 보냅니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈 소스 출판물에서 사용할 수 있지만, 이 코드를 출판물에서 재사용하는 것은 하우스 룰에 의해 관리됩니다.