Math equations in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

Math equations in PHP?

Post by J_Iceman05 »

Is it possible to use certain mathematic tools in php.
For example, pi is there a function that emulates pi in php, or would i have to make my own and use 3.14 (or more digits such as 3.141592653589) to imitate pi?

Also for things such as Euler's number e (which goes something to this effect 2.718281828459045)

Thanks in advanced for any help you can give.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

To get the value of pi, you can call pi() or use the constant M_PI. The value of e can be found with the M_E constant.

Pi function: http://www.php.net/pi
Math functions: http://www.php.net/manual/en/ref.math.php
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

actually i'm beginning work on a math library:-/ i don't know of anything built into PHP but once I get a new site design (hopefully within the next week) i'll start posting up math functions as open source.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

math related constants: (php 5.0.4)

Code: Select all

'M_E' => 2.71828182846,
    'M_LOG2E' => 1.44269504089,
    'M_LOG10E' => 0.434294481903,
    'M_LN2' => 0.69314718056,
    'M_LN10' => 2.30258509299,
    'M_PI' => 3.14159265359,
    'M_PI_2' => 1.57079632679,
    'M_PI_4' => 0.785398163397,
    'M_1_PI' => 0.318309886184,
    'M_2_PI' => 0.636619772368,
    'M_2_SQRTPI' => 1.1283791671,
    'M_SQRT2' => 1.41421356237,
    'M_SQRT1_2' => 0.707106781187,
    'INF' => INF,
    'NAN' => 0,
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

Thank you

Post by J_Iceman05 »

Thank you all very much for your input.
It's exactly what I was looking for.
This helps a lot.
Post Reply