[comp.lang.c] Allocating extra bits for mantissa of a float

rowe@pender.ee.upenn.edu (Mickey Rowe) (08/25/89)

I'm trying to find the zeroes of a function that blows up in an
extremely narrow range.  To find these zeroes, I'm searching for
places where the function becomes negative.  My problem is that the
width of the curve where the function is negative may be smaller than
1e-16 where the value of the indepenent variable is on the order of
1e+2.  This requires that the mantissa of my variable retain at least
(in some cases probably more) 18 significant figures.  Is there any
(even remotely simple) way to get such precision without building my
own computer?  I am currently working on a sun (I'm not sure of more
than that except that it uses SunOS release 4.0).

I have taken some tentative steps towards defining a structure of two
doubles, and using one for the most significant part of the number,
and one for the least significant part.  However, I've run into
problems even with addition of the members of such a structure due to
the roundoff errors in the least significant digits of the most
significant half of the structure (I hope that's clear).  I've posted
to this newsgroup because nearly all of my programming experience is 
in C, and I would like to solve my problem in this language.

Alternatively (on the off chance that anyone else has done this), what
I'm searching for is the characteristic values that lead to periodic
solutions (of period pi or 2*pi) of Mathieu's differential equation.
I'm attempting to use the infinite continued fraction as originally
determined by Ince, because it is the most general method of finding
the characteristic value for any type or order of solution.  This
problem only arises for the relatively high order solutions with small
values of the variable which is usually called q.  Any better methods
of determining the characteristic values under these conditions would
also be appreciated.

Thanks in advance.

rowe@pender.ee.upenn.edu     (Mickey Rowe)

mccalpin@masig3.ocean.fsu.edu (John D. McCalpin) (08/25/89)

In article <13884@netnews.upenn.edu>, rowe@pender.ee.upenn.edu (Mickey Rowe) writes:
> I'm trying to find the zeroes of a function that blows up in an
> extremely narrow range.  To find these zeroes, I'm searching for
> places where the function becomes negative.  My problem is that the
> width of the curve where the function is negative may be smaller than
> 1e-16 where the value of the indepenent variable is on the order of
> 1e+2.  This requires that the mantissa of my variable retain at least
> (in some cases probably more) 18 significant figures.  Is there any
> (even remotely simple) way to get such precision without building my
> own computer?  I am currently working on a sun (I'm not sure of more
> than that except that it uses SunOS release 4.0).

Although I have not used it for any significant programming, the 'bc'
program on your Sun has a C-like syntax and user-specifiable precision.
If it is a small piece of code, it might be relatively easy to re-write
it in bc.  The man page is a bit sketchy, but is should get you started.

There are reports of bugs in bc if you ask for more than about 47 decimal
digits of accuracy, but that should not be a difficulty for this problem.
Good luck....
--
John D. McCalpin - mccalpin@masig1.ocean.fsu.edu - mccalpin@nu.cs.fsu.edu
		   mccalpin@delocn.udel.edu

bill@twwells.com (T. William Wells) (08/25/89)

In article <13884@netnews.upenn.edu> rowe@pender.ee.upenn.edu (Mickey Rowe) writes:
: I'm trying to find the zeroes of a function that blows up in an
: extremely narrow range.  To find these zeroes, I'm searching for
: places where the function becomes negative.  My problem is that the
: width of the curve where the function is negative may be smaller than
: 1e-16 where the value of the indepenent variable is on the order of
: 1e+2.  This requires that the mantissa of my variable retain at least
: (in some cases probably more) 18 significant figures.  Is there any
: (even remotely simple) way to get such precision without building my
: own computer?  I am currently working on a sun (I'm not sure of more
: than that except that it uses SunOS release 4.0).

You've been spoiled by floating point! :-)

Seriously though, unless the computation requires a large exponent
range, do everything in fixed point, using as many shorts as you might
need to get the precision you want. Or even implement floating point
with your own exponent and mantissa in a structure. Either way will
give you complete control over precision and the like. Of course, they
may also be slower....

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com

cik@l.cc.purdue.edu (Herman Rubin) (08/25/89)

In article <13884@netnews.upenn.edu>, rowe@pender.ee.upenn.edu (Mickey Rowe) writes:
> I'm trying to find the zeroes of a function that blows up in an
> extremely narrow range.  To find these zeroes, I'm searching for
> places where the function becomes negative.  My problem is that the
> width of the curve where the function is negative may be smaller than
> 1e-16 where the value of the indepenent variable is on the order of
> 1e+2.  This requires that the mantissa of my variable retain at least
> (in some cases probably more) 18 significant figures.  Is there any
> (even remotely simple) way to get such precision without building my
> own computer?  I am currently working on a sun (I'm not sure of more
> than that except that it uses SunOS release 4.0).
> 
> I have taken some tentative steps towards defining a structure of two
> doubles, and using one for the most significant part of the number,
> and one for the least significant part.  However, I've run into
> problems even with addition of the members of such a structure due to
> the roundoff errors in the least significant digits of the most
> significant half of the structure (I hope that's clear).  I've posted
> to this newsgroup because nearly all of my programming experience is 
> in C, and I would like to solve my problem in this language.

Some machines have harware procedures for getting more floating point
precision than customary, but even this will require the use of machine
language instructions.  If these are not available, or if more precision
is needed, a multiple precision "package", which should, in general, use
the integer arithmetic, will be needed.  It may be possible to make an
appropriate modification of the algorithm to use a local expansion, in
which case multiple precision will only be required to get the constants.
< 
< Alternatively (on the off chance that anyone else has done this), what
< I'm searching for is the characteristic values that lead to periodic
< solutions (of period pi or 2*pi) of Mathieu's differential equation.
< I'm attempting to use the infinite continued fraction as originally
< determined by Ince, because it is the most general method of finding
< the characteristic value for any type or order of solution.  This
< problem only arises for the relatively high order solutions with small
< values of the variable which is usually called q.  Any better methods
< of determining the characteristic values under these conditions would
< also be appreciated.
< 
< Thanks in advance.
< 
< rowe@pender.ee.upenn.edu     (Mickey Rowe)
> 
> Alternatively (on the off chance that anyone else has done this), what
> I'm searching for is the characteristic values that lead to periodic
> solutions (of period pi or 2*pi) of Mathieu's differential equation.
> I'm attempting to use the infinite continued fraction as originally
> determined by Ince, because it is the most general method of finding
> the characteristic value for any type or order of solution.  This
> problem only arises for the relatively high order solutions with small
> values of the variable which is usually called q.  Any better methods
> of determining the characteristic values under these conditions would
> also be appreciated.
> 
> Thanks in advance.
> 
> rowe@pender.ee.upenn.edu     (Mickey Rowe)

A numerical analyst might (or might not) be able to help.
-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)