PHP: bcmod - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

bcmul bcdiv

Last updated: Sat, 27 Jan 2007

view this page in

# bcmod

(PHP 3, PHP 4, PHP 5)

bcmod -- Get modulus of an arbitrary precision number

## Description

string bcmod ( string left_operand, string modulus )

Get the modulus of the `left_operand` using `modulus`.

## Примеры

Пример 1. bcmod() example

`<?php echo bcmod('4', '2'); // 0 echo bcmod('2', '4'); // 2 ?>`

## Смотрите также

bcdiv().

add a note User Contributed Notes
bcmod
jmullan at visi dot com
24-Jul-2006 03:12
`<?php
function bc_is_even($int_str) {
if (0 < strlen($int_str)) {
return !((substr($int_str, -1)) % 2);
} else {
// error
return 0;
}
}
?>`
cristianDOTzuddas]NOSPAM[gmailDOTcom
24-Jul-2005 03:45
`BC Math is really cool, but has only 10 functions. So we MUST write other BC functions and share the code.
Here is a simple even/odd number check.
<?
function bc_is_even($int_str) {
if (strlen($int_str)>0) {
if (bcmod($int_str, 2)==='0')
return true;
else
return false;
}
else // error
return 0;
}
?>`
lauris at night dot lt
23-Dec-2003 08:04
`<?php
/**
* my_bcmod - get modulus (substitute for bcmod)
* string my_bcmod ( string left_operand, int modulus )
* left_operand can be really big, but be carefull with modulus :(
* by Andrius Baranauskas and Laurynas Butkus :) Vilnius, Lithuania
**/
function my_bcmod( $x, $y )
{
// how many numbers to take at once? carefull not to exceed (int)
$take = 5;
$mod = '';
do
{
$a = (int)$mod.substr( $x, 0, $take );
$x = substr( $x, $take );
$mod = $a % $y;
}
while ( strlen($x) );
return (int)$mod;
}
// example
echo my_bcmod( "7044060001970316212900", 150 );
?>`
add a note
bcmul bcdiv

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST