Skrevet av Emne: Programming: How to calculate pi  (Lest 4255 ganger)

ATC

  • Gjest
Programming: How to calculate pi
« på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • Not every programming environment has a constant for pi defined. How can this value be calculated?



    ATC

    • Gjest
    [Solved] Programming: How to calculate pi
    « Svar #1 på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • If you have functions for basic trigonometry available, you can use the following formula:

    pi = 4 * atan(1.0)

    The atan() function returns the arc tangent in radians and the value is mathematically defined to be between -PI/2 and PI/2 (inclusive).

    See "man 3 atan" for more info.