Ruby Tutorial Ruby Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Ruby - Math::PI Constant



The Ruby Math::PI is the ratio of the a circle's circumference to its diameter. It is approximately 3.14159.

Syntax

Math::PI

Example:

The example below shows some usage of Math::PI constant.

pi = Math::PI

puts "Math::PI = #{pi}" 
puts "Math.sin(pi/2) = #{Math.sin(pi/2)}"
puts "Math.cos(pi/2) = #{Math.cos(pi/2)}"
puts "Math.tan(pi/2) = #{Math.tan(pi/2)}"

puts 
puts "Radius of a circle = 10"
puts "Circumference of the circle =  #{2 * pi * 10}"
puts "Area of the circle =  #{pi * 10 * 10}"

The output of the above code will be:

Math::PI = 3.141592653589793
Math.sin(pi/2) = 1.0
Math.cos(pi/2) = 6.123233995736766e-17
Math.tan(pi/2) = 1.633123935319537e+16

Radius of a circle = 10
Circumference of the circle =  62.83185307179586
Area of the circle =  314.1592653589793

❮ Ruby Math Module

5