|
|
|
| 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 : |
3 of 5 (graded 3 times) |
| Viewed : |
4905 |
| 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
*/
?> |
|
| Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | 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. | | | Dollar Serial Number Validator Categories : PHP, Security, 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 | | | 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 | | | IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival. Categories : PHP, Algorithms, Security, URLs | | | 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 | | | Math operations on big numbers Categories : PHP, Math. | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | 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 | | | Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users). Categories : Algorithms, Email, PHP | |
|
|
|