|
|
|
| Title : |
Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
|
| Categories : |
Algorithms, PHP, Math. |
 Nick Bastin |
| Date : |
Jan 17th 1999 |
| Grade : |
2 of 5 (graded 4 times) |
| Viewed : |
7247 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Nick Bastin |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?php
/*
** mathlib v1.2.1 04/25/98 nbastin
**
** MathLib for PHP3 maintained by Nick Bastin <nbastin@rbbsystems.com>
** If you have source for functions that you would like to see added, or
** have functions that you would like to see added but don't know how to
** write yourself, please email me.
**
** All functions tested before distribution for functionality, and a
** reasonable bit of accuracy. However, these functions have
** not undergone extensive testing for their precision and accuracy, and
** you use at your own risk.
**
** That said, quite a few errors did turn up in testing, and I think I
** got them all. However, if you find an error, please let me know.
**
** To use these functions, include them in your PHP scripts
**
** - Nick Bastin <nbastin@rbbsystems.com>
*/
/*
** There's already a 'round' function in PHP...do we need this?
** Author: Bjorn Borud, Guardian Networks AS, <borud@guardian.no>
*/
function roundoff($v) {
if ( $v - floor($v) >= 0.5) {
return(ceil($v));
} else {
return(floor($v));
}
}
/*
** Converts degrees to radians
** Author: Bjorn Borud, Guardian Networks AS, <borud@guardian.no>
** Modified to break reliance on PI variable by Nick Bastin, <nbastin@rbbsystems.com>
*/
function deg2rad($degrees) {
return ((pi(void) * $degrees) / doubleval(180));
}
/*
** Converts radians to degrees
** Author: Nick Bastin, RBB Systems, <nbastin@rbbsystems.com>
*/
function rad2deg($radians) {
return (($radians * doubleval(180)) / pi(void));
}
/*
** Base-$base logarithm of $val. Useful for those evaluating logarithms in non-
standard bases
** Author: Nick Bastin, RBB Systems, <nbastin@rbbsystems.com>
*/
function baselog($base,$val) {
return ((log10($val))/(log10($base)));
}
/*
** Factorial function (Be careful, this number can grow out of control very quickly)
** Since you can't perform a factorial of a non-integer, the function casts $number
to an integer.
** Author: Nick Bastin, RBB Systems, <nbastin@rbbsystems.com>
*/
function factorial($number) {
$a = $b = (int) $number;
while ($b>1) {
--$b;
$a = $a * $b;
}
return $a;
}
/*
** Greatest Common Divisor function - Returns the greatest common divisor of $x and
$y
** Author: Nick Bastin, RBB Systems, <nbastin@rbbsystems.com>
*/
function gcd($x,$y) {
$x = abs($x);
$y = abs($y);
if ( $x + $y = 0 ) {
return "ERROR";
} else {
while ($x > 0) {
$z = $x;
$x = $y % $x;
$y = $z;
}
return $z;
}
}
/*
** Functions coming soon:
**
** - Infinitely precise division function
** - Factoring function
** - Prime number evaluation
** - Prime number generator
*/
?> |
|
| Prime number finder (Sieve of Erastothenes) Categories : PHP, Algorithms, Math. | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Reverse a given number Categories : PHP, Beginner Guides, Algorithms, Math. | | | Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP, Math., Algorithms | | | How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | A very simple and efficient split bar the B-Z bar , for mysql and php ...
Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms | | | Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers. Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms | | | Prime Spiral is a image plotted with all the primes in a number spiral.
Categories : Algorithms, Graphics, GD image library, Math. | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | Boolean Keyword Interpreter Categories : PHP, Algorithms, Search Engines | | | IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival. Categories : PHP, Algorithms, Security, URLs | | | How to Generate a random 8 character string in php3? Categories : PHP, Algorithms | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | Browse a MySQL database & draw a tree view & load final items into a template page. Categories : MySQL, Complete Programs, Algorithms, PHP, Databases | | | Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms | |
| |
| |
|