Skip to content

Blockzez/double-conversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Double Conversion Module

A double conversion module for Luau based off Google's double conversion.

DoubleToStringConverter

The double to string converter class.

DoubleToStringConverter.Flags

The possible bit combination of the flags enum: NO_FLAGS - No flags

EMIT_POSITIVE_EXPONENT_SIGN - When the number is in the exponential format,
it emits the "+" sign for positive exponents.

EMIT_TRAILING_DECIMAL_POINT - When the number is in the decimal format,
it emits a trailing decimal point ".".

EMIT_TRAILING_ZERO_AFTER_POINT - When the number is in the decimal format,
it emits a trailing "0" after the point, EMIT_TRAILING_DECIMAL_POINT must
be enabled

UNIQUE_ZERO - -0 does not display the minus sign "-"

DoubleToStringConverter.Format

The format for its string representation: AUTO - Print the value in the decimal format if it's in the range of [10^decimal_in_shortest_low; 10^decimal_in_shortest_high[

DECIAML - Print the value in the decimal format

EXPONENTIAL - Print the value in the exponential format

DoubleToStringConverter.new

function DoubleToStringConverter.new(
	flags: number,
	infinity_symbol: string?,
	nan_symbol: string?,
	exponent_symbol: string,
	decimal_in_shortest_low: number,
	decimal_in_shortest_high: number,
	min_exponent_width: number
): DoubleToStringConverter

The flag argument takes DoubleToStringConverter.Flags bit combination

infinity_symbol and nan_symbol provide a string representation of these values, if these are nil then if you enter these value, they'll return nil as well

exponent_symbol is the symbol that represents exponents, usually 'e' or 'E'

When the format argument is provided as AUTO, it'll represent the numbers in decimal format if the range [10^decimal_in_shortest_low; 10^decimal_in_shortest_high[ and exponential otherwise

min_exponent_width zero fills the exponent integer digit. Basically, adding leading '0's to the exponent until it's at least min_exponent_width long. It only accepts integers from 1 to 5 so the exponent may never have more than 5 digits in total.

DoubleToStringConverter:ToShortest

function DoubleToStringConverter:ToShortest(value: number, format: number?)

Converts the double to its shortest decimal representation that correctly represents the double. The format argument takes the DoubleToStringConverter.Format argument enum as described.

DoubleToStringConverter:ToExact

function DoubleToStringConverter:ToExact(value: number, format: number?)

Converts the double to its exact decimal representation. The format argument takes the DoubleToStringConverter.Format argument enum as described.

DoubleToDecimalConverter

DoubleToDecimalConverter.ToShortest

function DoubleToDecimalConverter.ToShortest(value: number): ({ number }?, number?, number?)

Returns the shortest decimal representation of double converted to decimal in array of table with the length and scale by the power of ten. Zero, infinity, and NaN will return nil

DoubleToDecimalConverter.ToExact

function DoubleToDecimalConverter.ToExact(value: number): ({ number }?, number?, number?)

Returns the exact decimal representation of double converted to decimal in array of table with the length and scale by the power of ten

DecimalToDoubleConverter

DecimalToDoubleConverter.ToDouble

function DecimalToDoubleConverter.ToDouble(value: { number }, scale: number?, i: number?, j: number?): number?

Converts decimal array from i to j to a double with scale in power of tens

Contents
  1. DoubleToStringConverter
    1. DoubleToStringConverter.Flags
    2. DoubleToStringConverter.Format
    3. DoubleToStringConverter.new
    4. DoubleToStringConverter:ToShortest
    5. DoubleToStringConverter:ToExact
  2. DoubleToDecimalConverter
    1. DoubleToDecimalConverter.ToShortest
    2. DoubleToDecimalConverter.ToExact
  3. DecimalToDoubleConverter
    1. DecimalToDoubleConverter.ToDouble

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages