## Function: bcmod version 475

 Function: Description: Get the modulus of the left_operand using modulus.
 Version: 475 Status: obsolete Date: 2012-03-16 20:56 Summary: Fixing imbalanced parens syntax error. Programmer: jj5
Code
```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
```
```/*
Note: this function is a hack, and it only supports the use cases I require at
the moment, being: arbitrary precision integer left_operand and native precision positive integer modulus (must fit in a native number, i.e. a double).
*/
function bcmod( left_operand, modulus ) {
var i, d;
function split( operand ) {
var parts = operand.split( '.' );
i = parts[ 0 ];
d = '0.' + parts.length > 1 ? parts[ 1 ] : '0';
}
modulus = Math.round( parseFloat( modulus ) );
modulus = abs( modulus ).toString();
if ( modulus < 1 ) { return null; }
var take = 4;
var modulus_limit = Math.pow( 10, take );
if ( modulus >= modulus_limit  ) {
var result = 0;
split( last_operand );
read_length = i.length < take ? i.length : take;
var result = i.substr( 0, take );
i = i.substr( take );
return result;
}
do {
result = ( result * modulus_limit + parseInt( read() ) ) % modulus;
}
while ( i.length > 0 );
result += parseFloat( d );
var test = result - modulus;
result = test < 0 ? result : test;
return result.toString();
}
```
[top]