One way to slice a pie
-
I found this line of Lua code in a graphical application and thought it qualified as both weird and wonderful.
local PI = math.asin(1) * 2
What an interesting little trick to calculate Pi. Unfortunately the math library has math.pi. If that was not implemented in an earlier version I would write the whole 3.14etc. rather then use this mathematical trick.
-
I found this line of Lua code in a graphical application and thought it qualified as both weird and wonderful.
local PI = math.asin(1) * 2
What an interesting little trick to calculate Pi. Unfortunately the math library has math.pi. If that was not implemented in an earlier version I would write the whole 3.14etc. rather then use this mathematical trick.
genius :laugh:
In code we trust !
-
I found this line of Lua code in a graphical application and thought it qualified as both weird and wonderful.
local PI = math.asin(1) * 2
What an interesting little trick to calculate Pi. Unfortunately the math library has math.pi. If that was not implemented in an earlier version I would write the whole 3.14etc. rather then use this mathematical trick.
Fueled By Caffeine wrote:
I would write the whole 3.14etc
Good luck with that! ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Fueled By Caffeine wrote:
I would write the whole 3.14etc
Good luck with that! ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Four decimal places ought to be good enough for anyone.
You'll never get very far if all you do is follow instructions.
-
I found this line of Lua code in a graphical application and thought it qualified as both weird and wonderful.
local PI = math.asin(1) * 2
What an interesting little trick to calculate Pi. Unfortunately the math library has math.pi. If that was not implemented in an earlier version I would write the whole 3.14etc. rather then use this mathematical trick.
In my view, in the absence of a math.pi this is a far more sensible option than the whole 3.14etc. It's not a trick.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
-
In my view, in the absence of a math.pi this is a far more sensible option than the whole 3.14etc. It's not a trick.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
Phil J Pearson wrote:
more sensible option than the whole 3.14etc
Meh. Copy-and-paste http://www.piday.org/million/[^]
You'll never get very far if all you do is follow instructions.
-
I found this line of Lua code in a graphical application and thought it qualified as both weird and wonderful.
local PI = math.asin(1) * 2
What an interesting little trick to calculate Pi. Unfortunately the math library has math.pi. If that was not implemented in an earlier version I would write the whole 3.14etc. rather then use this mathematical trick.
Interesting, that
asin
ine use of a math function. -
In my view, in the absence of a math.pi this is a far more sensible option than the whole 3.14etc. It's not a trick.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
While
PI = math.asin(1) * 2
may be mathematically correct, it's probably not the most accurate representation of π you could create. It depends upon the arcsine function implementation. You might get lucky in case they shortcut the value for an argument of 1, and simply return the library's value of π. If not, they're going to do the arcsine calculation using a numerical method that will approximate something close to π. In other words, it would be more precise if the library simply gave you its value of π. For casual calculations, the difference may not matter. If you're doing a simulation, having your value of π off by a couple bits could have long-term consequences.Software Zen:
delete this;