PINE LIBRARY
Cập nhật fraction

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. <<
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
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
Phát hành các Ghi chú
v2Added:
Fraction
Fraction UDT for representing fractional numbers
Fields:
numerator (series int): (int) Numerator of the fraction
denominator (series int): (int) Denominator of the fraction
Updated:
make(_numerator, _denominator)
Create a new Fraction object
Parameters:
_numerator (int): (int) Numerator of the fraction
_denominator (int): (int) Denominator of the fraction
Returns: (Fraction) Fraction object
add(_fraction, _fraction2)
Perform add operation (left adds right onto )
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (Fraction) Resulting Fraction object
subtract(_fraction, _fraction2)
Perform subtract operation (left subtracts right from )
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (Fraction) Resulting Fraction object
multiply(_fraction, _fraction2)
Perform multiply operation (left multiplies by right )
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (Fraction) Resulting Fraction object
divide(_fraction, _fraction2)
Perform divide operation (left divides by right )
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (Fraction) Resulting Fraction object
negative(_fraction)
Perform Negative number inversion ie: (-1/2 => 1/2) or (3/5 => -3/5)
Parameters:
_fraction (Fraction): (Fraction) Fraction Object to invert to/from negative
Returns: (Fraction) Resulting Fraction object
isSmaller(_fraction, _fraction2)
Check if first fraction is smaller
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (bool) True if smaller, false if bigger
isLarger(_fraction, _fraction2)
Check if first fraction is larger
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (bool) True if larger, false if smaller
isEqual(_fraction, _fraction2)
Check if first fraction is equal
Parameters:
_fraction (Fraction): (Fraction) left side Fraction Object
_fraction2 (Fraction): (Fraction) right side Fraction Object
Returns: (bool) True if equal, false if not equal
fromDec(_source, _epsilon, _iterations)
Convert Decimal to Fraction object
note : this is my own Negative Number Capable (tiny speed loss)
adaptation of the fastest algo out there
Exclusive for Tradingview.
Parameters:
_source (float)
_epsilon (int): (int) (OPTIONAL) to precision 0's after dec 0.0000 -> epsilon 0's
_iterations (int): (int) (OPTIONAL) Maximum iterations Till give up
Returns: (Fraction) Fraction object
toDec(_fraction)
Convert Fraction object to Decimal Output
Parameters:
_fraction (Fraction): (Fraction) Fraction Object
Returns: (float) Decimal representation of fraction
toString(_fraction, _wholenum)
Create "A/B" or "A and B/C" String Value of Fraction.
Parameters:
_fraction (Fraction): (Fraction) Fraction Object to format as string
_wholenum (bool): (bool) Optional, Output as whole number and fraction if possible
Returns: (string) String as (-)? A and B/C format
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.