My favorites
▼
|
Sign in
klenwell
klenwell open source repository
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
pastebin
/
bc_demo.php
r299
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
A Demonstration of the PHP BC Library
How to use really big numbers in PHP
Usage:
path/to/bc_demo.php
Reference
http://www.php.net/manual/en/ref.bc.php
*/
$max = 1000;
foreach ( range(1,$max) as $x )
{
if (
! ( pow(2,$x)+1 > pow(2,$x) ) ||
! ( pow(2,$x)-1 < pow(2,$x) ) ||
! ( pow(2,$x-1)*2 == pow(2,$x) )
) break;
}
$maxpow = $x-1;
$maxint = bcpow(2, $maxpow);
$Result['op'] = "max supported int: 2^$maxpow or $maxint\n";
foreach ( range(1,$max) as $x )
{
if (
! ( bccomp(bcadd(bcpow(2,$x),1), bcpow(2,$x)) == 1 ) ||
! ( bccomp(bcsub(bcpow(2,$x),1), bcpow(2,$x)) == -1 ) ||
! ( bccomp(bcmul(bcpow(2,$x-1),2), bcpow(2,$x)) == 0 )
) break;
}
$maxpow = $x-1;
$maxint = bcpow(2, $maxpow);
$Result['bc'] = "max supported int >= 2^$maxpow or $maxint\n";
printf("<pre>%s</pre>", print_r($Result,1));
?>
Show details
Hide details
Change log
r231
by klenwell on Mar 14, 2009
Diff
adding php bc demo
Go to:
/trunk/pastebin/bc_demo.php
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 938 bytes, 46 lines
View raw file
Powered by
Google Project Hosting