[CLN-list] floating point error

Elvis Dieguez edieguez at gmail.com
Mon Jul 4 17:04:26 CEST 2005


Hi,

 This a bit difficult to explain but let me try...

 The boost matrix library uses templates extensively in its code. I am
 using the library in the following way (for example)

   matrix<cl_F> G(3,3), T(3,3);

   G(0,0) = "-0.3e-5_5000";
   G(0,1) = "0.5e-5_5000";
   G(0,2) = "0.8e-5_5000";

   ... etc

 When I try the following

   T(0,0) = G(0,0);
   for(int i = 0; i < 10; i++)
     T(0,0) = T(0,0)*G(0,0);

   cout << endl << T << endl;

 It works just fine, which is no surprise since I specified a 5000
 precision. However, if I try the following

   T = prod(G,G);
   for(int i = 0; i < 10; i++)
     T = prod(T,G);

   cout << endl << T << endl;

 I get a floating point underflow error. I think the problem is the call
 to prod(*,*) creates a matrix where the cl_F matrix entries are defined
 with some smaller, default precision (probably equal to that of a long
 float from what I can tell).

 Is there a way to set the default precision for all created cln
 variables? If not, I will have to write my own matrix multiplication
 function... something I would not rather do if at all possible.

 I've looked at the cln documentation and it appears

 |float_format_t default_float_format|

     Global variable: the default float format used when converting
     rational numbers to floats.


 there is a way but I do not quite understand how one might change the
 default precision.


 Thank you for your help.
 Elvis Dieguez

-- 
...how one lives is so far distant from how one ought to live, that he
who neglects what is done for what ought to be done, sooner effects
his ruin than his preservation; for a man who wishes to act entirely
up to his professions of virtue soon meets with what destroys him
among so much that is evil.

-- Nicolo Machiavelli, The Prince (1515)




More information about the CLN-list mailing list