Java Reference
In-Depth Information
result.append('-');
number # -number;
}
int i;
int power # ( int )Math.floor(Math.log(number ! EPSILON/2)
/Math.log(base));
if (power<0) power # 0;
double divider # Math.pow(base,power);
int num_digits # 0;
double divResult, cipher;
for ( int i # power;
(number>EPSILON && num_digits<MAX_PRECISION) ||
i > # -1; —i){
divResult # number / divider;
cipher # Math.floor((number ! EPSILON/2) / divider);
if (divider < 1.0){
num_digits !! ;
if (num_digits ## 1) result.append('.');
}
result.append(digits.charAt(( int )cipher));
number - # cipher * divider;
divider / # base;
}
return result.toString();
}
}
The Base class provides almost everything required to define a number
base. The only thing left to be specified is the base together with the digits.
The concrete number bases have only to provide these two parameters in
addition to the name of the base.
public class BinaryBase extends Base{
public BinaryBase() {
super ("bin", 2 ,"01");
}
}
public class DecimalBase extends Base {
public DecimalBase() {
super ("dec", 10 ,"0123456789");
}
}
public class HexBase extends Base {
public HexBase() {
super ("hex", 16 ,"0123456789ABCDEF");
}
}
Search WWH ::




Custom Search