Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lua as usually configured uses your platform's usual double-precision floating point format to store all numbers. For <em>most</em> desktop platforms today, that will be the 64-bit IEEE-754 format. The <a href="http://lua-users.org/wiki/FloatingPoint" rel="noreferrer">conventional wisdom</a> is that integers in the range -1E15 to +1E15 can be safely assumed to be represented exactly.</p> <p>In any case, the <a href="http://www.lua.org/manual/5.1/manual.html#pdf-string.format" rel="noreferrer"><code>string.format()</code></a> function passes its arguments through (with some minor tweaks) to the platform's implementation of <a href="http://www.cplusplus.com/reference/clibrary/cstdio/printf/" rel="noreferrer"><code>printf()</code></a>. The format string understood by <code>printf()</code> includes <code>%e</code> and <code>%E</code> to force "scientific" notation, and <code>%f</code> to force plain decimal notation. In addition, <code>%g</code> and <code>%G</code> choose the shortest notation.</p> <p>For example:</p> <pre> E:\...>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > a = 1e17/3 > print(string.format("%f",a)) 33333333333333332.000000 > print(string.format("%e",a)) 3.333333e+016 > print(string.format("%.0f",a)) 33333333333333332 </pre> <p>Note that if the value fits within a 32-bit signed integer range, you can also use the <code>%d</code> format. However, results are not well defined if the value exceeds that range. System timestamps in microseconds are likely to exceed the 32-bit range.</p> <p>If 16 decimal digits is not enough precision, there are several choices available for increased precision. </p> <p>First, it would not be difficult to package a true 64-bit integer in a <code>userdata</code> along with a suitable set of arithmetic metamethods. This gets discussed occasionally on the <a href="http://www.lua.org/lua-l.html" rel="noreferrer">Lua mailing list</a>, but I don't recall seeing a completed module released by anyone.</p> <p>Second, one of the Lua authors has released two modules supporting arbitrary precision arithmetic: <a href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/" rel="noreferrer">lbc and lmapm</a>. Both are found at that page.</p> <p>Third, casual searching in Google readily turns up several other math library wrappers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload