note 25079 added to function.floor

From: Date: Tue, 10 Sep 2002 08:08:35 +0000
Subject: note 25079 added to function.floor
Groups: php.notes 
Request: Send a blank email to php-notes+get-36426@lists.php.net to get a copy of this message
mathematical functions lack a floating point version of the modulo operation, which returns the difference between the floor() of the argument and the argument itself: function fmod($value) { return $value - floor($value); } Very useful with trigonometric functions to reduce the angle argument to a circle that includes angle 0. Useful also to reduce an arbitrarily large floating point value into an entropy source, by first transforming this value into a pair using logarithm functions with distinct bases (add 1 if the function can return 0, to avoid floating point errors with logarithms!): $f = 1 + @disk_free_space("/tmp"); $r = (int)(fmod(Log($f)) * 0x7FFFFFFF) ^ (int)(fmod(Log10($f)) * 0x7FFFFFFF) Then $r can be used as a good entropy source, if the free space in your temporary folder used by PHP is constantly evolving within a large range of values. You can combine this value by xoring it with other values such as time(), (int)microtime(), ip2long($_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], getmypid(), ... -- http://www.php.net/manual/en/function.floor.php http://master.php.net/manage/user-notes.php?action=edit+25079 http://master.php.net/manage/user-notes.php?action=delete+25079 http://master.php.net/manage/user-notes.php?action=reject+25079

« previous php.notes (#36426) next »