Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. One way to slice a pie

One way to slice a pie

Scheduled Pinned Locked Moved The Weird and The Wonderful
announcement
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fueled By Decaff
    wrote on last edited by
    #1

    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.

    N Richard DeemingR P B 4 Replies Last reply
    0
    • F Fueled By Decaff

      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.

      N Offline
      N Offline
      Nguyen H H Dang
      wrote on last edited by
      #2

      genius :laugh:

      In code we trust !

      1 Reply Last reply
      0
      • F Fueled By Decaff

        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.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        P 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Four decimal places ought to be good enough for anyone.

          You'll never get very far if all you do is follow instructions.

          1 Reply Last reply
          0
          • F Fueled By Decaff

            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.

            P Offline
            P Offline
            Phil J Pearson
            wrote on last edited by
            #5

            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.

            P G 2 Replies Last reply
            0
            • P Phil J Pearson

              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.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • F Fueled By Decaff

                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.

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                Interesting, that asinine use of a math function.

                1 Reply Last reply
                0
                • P Phil J Pearson

                  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.

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #8

                  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;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups