IT Community - Software Programming, Web Development and Technical Support

Mathematical functions in PHP

This is a discussion on Mathematical functions in PHP within the PHP Programming forums, part of the Web Development category; Hi Buddies, Shall we discuss about mathematical functions. i want to know more about that for implementing in My site ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 12:37 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 288
Falcon is on a distinguished road
Default Mathematical functions in PHP

Hi Buddies,

Shall we discuss about mathematical functions. i want to know more about that for implementing in My site

Thanks
Falcon
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-15-2008, 12:52 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

hi,
actually These math functions will only handle values within the range of the integer and float types on your computer.

The math functions are part of the PHP core. There is no installation needed to use these functions.
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 07:21 AM
sureshbabu sureshbabu is offline
D-Web Programmer
 
Join Date: Jul 2007
Location: India
Posts: 97
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: Mathematical functions in PHP

abs
It returns absolute value
Description
number abs ( mixed $number )
Examples

<?php
$abs = abs(-4.2); // $abs = 4.2; (double/float)
$abs2 = abs(5); // $abs2 = 5; (integer)
$abs3 = abs(-5); // $abs3 = 5; (integer)
?>
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 02:15 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

ceil() returns the next highest integer value by rounding up value if necessary. The return value of ceil() is still of type float as the value range of float is usually bigger than that of integer.

Example:
PHP Code:
<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-16-2008, 02:16 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

floor() returns the next lowest integer value by rounding down value if necessary. The return value of floor() is still of type float because the value range of float is usually bigger than that of integer.

example:
PHP Code:
<?php
echo floor(4.3);   // 4
echo floor(9.999); // 9
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-16-2008, 02:18 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

round() returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

Example:
PHP Code:
<?php
echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.60);      // 4
echo round(1.955832);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.0452);    // 5.05
echo round(5.0552);    // 5.06
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-16-2008, 02:41 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Mathematical functions in PHP

Hi,


max() returns the numerically highest of the parameter values.If the first and only parameter is an array, max() returns the highest value in that array. If the first parameter is an integer, string or float, you need at least two parameters and max() returns the biggest of these values. You can compare an unlimited number of values.
__________________
Regards,
Senraj.A

Last edited by senraj : 04-16-2008 at 02:49 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-16-2008, 02:43 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Mathematical functions in PHP

Hi,

max() function example:

PHP Code:
echo max(13567); 
echo 
"</br>";
echo 
max(array(245));

output :
7

__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-16-2008, 07:47 AM
sureshbabu sureshbabu is offline
D-Web Programmer
 
Join Date: Jul 2007
Location: India
Posts: 97
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: Mathematical functions in PHP

cos()
The acos() function returns the arccosine of a number as a numeric value value between 0 and PI radians.

Syntax
acos(x)

Example
In this example we will get the arccosine of different numbers:

<?php
echo(acos(0.64) . "<br />");
echo(acos(0) . "<br />");
echo(acos(-1) . "<br />");
echo(acos(1) . "<br />");
echo(acos(2))
?>
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-16-2008, 07:48 AM
sureshbabu sureshbabu is offline
D-Web Programmer
 
Join Date: Jul 2007
Location: India
Posts: 97
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: Mathematical functions in PHP

rad2deg()
The rad2deg() function converts a radian number to its degree.

Syntax
rad2deg(radian_number)
Example
<?php
$rad = M_PI;
$deg = rad2deg($rad);
echo "$rad radians is equal to $deg degrees";
?>
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 04-16-2008, 10:43 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

exp() calculates the exponent of e (the Neperian or Natural logarithm base)

example:
PHP Code:
<?php
echo exp(12) . "\n";
echo 
exp(5.7);
?>
The above example will output:
Code:
1.6275E+005
298.87
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-16-2008, 10:44 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

pow() returns base raised to the power of exp. If possible, this function will return an integer.

If the power cannot be computed, a warning will be issued, and pow() will return FALSE. Since PHP 4.2.0 pow() doesn't issue any warning.

And PHP cannot handle negative bases

Example:
PHP Code:
<?php

var_dump
(pow(28)); // int(256)
echo pow(-120); // 1
echo pow(00); // 1

echo pow(-15.5); // error

?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-16-2008, 10:46 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,158
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Mathematical functions in PHP

sqrt() returns the square root of arg.

example:
PHP Code:
<?php
// Precision depends on your precision directive
echo sqrt(9); // 3
echo sqrt(10); // 3.16227766 ...
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-17-2008, 02:48 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 288
Falcon is on a distinguished road
Default Re: Mathematical functions in PHP

Hi

is_finite()
The is_finite() function returns true if the specified value is a finite number, otherwise it returns nothing.
PHP Code:
<?php
echo is_finite(2) . "<br />";
echo 
is_finite(log(0)) . "<br />";
echo 
is_finite(2000);
?>
Regards
Falcon
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 04-17-2008, 02:50 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 288
Falcon is on a distinguished road
Default Re: Mathematical functions in PHP

Hi

acos()
The acos() function returns the arccosine of a number as a numeric value value between 0 and PI radians
PHP Code:
<?php
echo(acos(0.64) . "<br />");
echo(
acos(0) . "<br />");
echo(
acos(-1) . "<br />");
echo(
acos(1) . "<br />");
echo(
acos(2))
?>
Regards
Falcon
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 04-17-2008, 02:54 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 288
Falcon is on a distinguished road
Default Re: Mathematical functions in PHP

Hi

cos()
The cos() returns the cosine of a number.
PHP Code:
<?php
echo(cos(3) . "<br />");
echo(
cos(-3) . "<br />");
echo(
cos(0) . "<br />");
echo(
cos(M_PI) . "<br />");
echo(
cos(2*M_PI))
?>
OutPut will be
Code:
-0.9899924966004454
-0.9899924966004454
1
-1
1
Regards
Falcon

Last edited by Falcon : 04-17-2008 at 02:58 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 04-17-2008, 03:00 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 288
Falcon is on a distinguished road
Default Re: Mathematical functions in PHP

hi

cosh()
The cosh() function returns the hyperbolic cosine of a number (equivalent to (exp(x) + exp(-x)) / 2).
PHP Code:
<?php
echo(cosh(3) . "<br />");
echo(
cosh(-3) . "<br />");
echo(
cosh(0) . "<br />");
echo(
cosh(M_PI) . "<br />");
echo(
cosh(2*M_PI))
?>
OutPut wiil be
Code:
10.0676619958
10.0676619958
1
11.5919532755
267.746761484
Regards
Falcon
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 04-17-2008, 07:00 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 180
saravanan is on a distinguished road
Default Re: Mathematical functions in PHP

<?php
echo(rand() . "<br />");17757
echo(rand() . "<br />");3794
echo(rand(10,100)) ;97 it generate rand number between 1-100

?>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 04-17-2008, 07:04 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 180
saravanan is on a distinguished road
Default Re: Mathematical functions in PHP

<?php
echo is_nan(200) . "<br />";
echo is_nan(acos(1.01));
?>

The is_nan() function returns true if the specified value is "not a number", otherwise it returns nothing.
answer for above code
1.nothing
2.true ,its means it not a number
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 04-17-2008, 07:07 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 180
saravanan is on a distinguished road
Default Re: Mathematical functions in PHP

<?php
echo decbin("3") . "<br />";
echo decbin("1") . "<br />";
echo decbin("1587") . "<br />";
echo decbin("7");
?>

this function to convert the decimal number into binary number
Answer for above code
11
1
11000110011
111
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote