PHP sin() Function

PHPServer Side ProgrammingProgramming

Definition and Usage

The sin() function returns the sine ratio of given angle in radians. In trigonometry, sine of an angle is defined as ratio of lengths of opposite side and hypotenuse.

sin(x) = opposite/hypotenuse

If x=90 degree, sin(x) = 1 as opposite side of right angle is a hypotenuse

This function returns a float value.

Syntax

sin ( float $arg ) : float

Parameters

Sr.NoParameter & Description
1arg
A floating point value that represents angle in radians

Return Values

PHP sin() function returns sine ratio of given parameter.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

 Live Demo

Following example calculates sin(pi/2) and returns 1. Sine ratio of 90 deg is 1 −

<?php
   $arg=M_PI_2;//represents pi/2 i.e. 90 deg.
   $val=sin($arg);
   echo "sin(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

sin(1.5707963267949) = 1

Example

 Live Demo

Following example uses deg2rad() function to convert degrees to radians and then uses sin(30) −

<?php
   $arg=deg2rad(30);
   $val=sin($arg);
   echo "sin(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

sin(0.5235987755983) = 0.5

Example

 Live Demo

Let's check find out sin(0). It returns 0 −

<?php
   $arg=0;
   $val=sin($arg);
   echo "sin(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

sin(0) = 0

Example

 Live Demo

Following example computes sin(pi) and retuns 1.2246467991474E-16 which is nearly equal to 0

<?php
   $arg=M_PI; // pi
   $val=sin($arg);
   echo "sin(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

sin(3.1415926535898) = 1.2246467991474E-16
raja
Published on 30-Jun-2020 10:53:38
Advertisements