This topic is now archived and is closed to further replies.


high precission numbers?

Recommended Posts

I''m trying to find a way to work with high precission numbers. Specifically, I need to be able to calculate a movement of 1 inch at a range of a million miles from the origin of the coordinate system. I''m working on a class to hold the value. but I''m haveing the following problem, how do I convert a number to text. i.e. Exponant = 1 Mantasia = 1b the output should be 1 Exponant = 2 Mantasia = 1b the output should be 4 I''ve already created the class object and I''m working on the math functions but I have no way to check the results because I can''t figure out how to convert it to a text display. I''m currently working with a 32 bit Exponant and a 16384 bit Mantasia but I''m planning on upping the size of the Mantasia as soon as I figure this out so I can see if the code even works.

Share this post

Link to post
Share on other sites
If you already have the +-/* routines, you can print the number using your FP routines. This is equivalent to using floating point arithmetic to print the number instead of decomposing it using integer instructions.

The floating point printing algorithm goes like this:

public StringBuffer append(double f) {
// check for zero
if (f == 0.0) {
return this;
// init exponent
int exp = 0;
// get number into scientific notation
if (f > 10.0) {
while (f > 10.0) {
f /= 10.0;
else if (f < 1.0) {
while (f < 1.0) {
f *= 10.0;
// append number
int digit = (int) f; // get non fractional part
append((char) (digit + '0'));
// do 13 digit fractional precision
for (int i = 0; i < 13; i++) {
f -= (double) digit; // subtract digit from number
f *= 10.0; // shift number by 10
digit = (int) f; // get non fractional part
append((char) (digit + '0')); // append digit to string buffer
// append exponent
if (exp >= 0)
// return string buffer
return this;

Edited by - bpj1138 on October 20, 2001 6:37:17 AM

Share this post

Link to post
Share on other sites