useful_programs
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
useful_programs [2020/07/30 15:07] – atolstov | useful_programs [2021/02/12 10:15] – [Curve handler] emozolyak | ||
---|---|---|---|
Line 914: | Line 914: | ||
</ | </ | ||
Example of usage: | Example of usage: | ||
- | <code lua - Getter> | + | <code lua - curves getter> |
include " | include " | ||
Line 925: | Line 925: | ||
end | end | ||
+ | </ | ||
+ | |||
+ | ===== Processing double float numbers ===== | ||
+ | |||
+ | <code lua> | ||
+ | function d2float(n) | ||
+ | |||
+ | local function getBits(input_num, | ||
+ | -- works with number and len | ||
+ | local tab = {} | ||
+ | local max_i = length - 1 | ||
+ | local remainder = input_num | ||
+ | | ||
+ | for i = max_i, 0, -1 do | ||
+ | local bit_ = (remainder - 2^i >= 0) and ' | ||
+ | table.insert(tab, | ||
+ | end | ||
+ | return tab | ||
+ | end | ||
+ | |||
+ | local function getNumberFromTab(tab, | ||
+ | local result_str = "" | ||
+ | |||
+ | for i = start, (start + length - 1) do | ||
+ | result_str = result_str .. tostring(tab[i]) | ||
+ | end | ||
+ | return tonumber(result_str, | ||
+ | end | ||
+ | |||
+ | local NaN = tonumber(" | ||
+ | local result_tab = {} | ||
+ | |||
+ | -- get a table of " | ||
+ | if (type(n) == " | ||
+ | result_tab = getBits(n, 64) | ||
+ | elseif (type(n) == " | ||
+ | local tmpS = '' | ||
+ | for i = 1, #n do | ||
+ | tmpS = tmpS .. table.concat(getBits(n[i], | ||
+ | end | ||
+ | |||
+ | for j=1, #tmpS do | ||
+ | table.insert(result_tab, | ||
+ | end | ||
+ | else | ||
+ | ERROR(" | ||
+ | end | ||
+ | |||
+ | local sign, exp, mantissa = 0, 0, 0 | ||
+ | local fraction_table = {} -- fraction part table | ||
+ | |||
+ | sign = ((result_tab[1] == " | ||
+ | exp = getNumberFromTab(result_tab, | ||
+ | |||
+ | for i = 13, 64 do | ||
+ | table.insert(fraction_table, | ||
+ | end | ||
+ | |||
+ | for j = 1, 52 do | ||
+ | if (fraction_table[j]== " | ||
+ | mantissa = mantissa +(2 ^(-1 * j)) -- calc. mantissa by summing individual bits | ||
+ | end | ||
+ | end | ||
+ | mantissa = mantissa + 1 | ||
+ | local result_num = sign * (2 ^ (exp - 1023)) * mantissa | ||
+ | |||
+ | ----------------------------------------- exceptions ---------------------------------- | ||
+ | if exp == 0 then -- subnormals | ||
+ | | ||
+ | end | ||
+ | |||
+ | if exp == 0x7ff then -- nan | ||
+ | | ||
+ | end | ||
+ | |||
+ | | ||
+ | end | ||
</ | </ | ||
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak