|
|
|
| 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 : |
6226 |
| 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
*/
?> |
|
| How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | 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 | | | 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. | | | SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge
response login algorithms over an insecure connection. Categories : Algorithms, PHP, Security | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | | | decoct -- Decimal to octal Categories : PHP, PHP Functions, Math. | | | 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 | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Calculate Body Mass Index Categories : PHP, Algorithms, Regexps | | | Timer - a class that uses microtime() to provide easy calculation of elapsed times Categories : Algorithms, PHP, PHP Classes | | | Find the day of the week for any given year/month/day. Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides | | | PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP, Algorithms, Security, Authentication, Encryption | | | quick sort for associative arrays Categories : Algorithms, Arrays, PHP | |
|
|