Thread: exp: OVERFLOW error

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The range for exp() when it's implemented as a double function will be about +/-700 for the input value.

    If you can find/implement exp() as a long double, you may get about +/-11000 as the input to exp. But it seems like your compiler doesn't support this.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    The only valid options are:
    1. Write an arbitrary precision math library.
    2. Find and use an arbitrary precision math library.
    3. Use something other than C to solve your problem, Mathematica, Matlab to name a few.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by xuftugulus View Post
    The only valid options are:
    1. Write an arbitrary precision math library.
    2. Find and use an arbitrary precision math library.
    3. Use something other than C to solve your problem, Mathematica, Matlab to name a few.
    Well, I guess you can still use the expl() version if there is support for it on the system. I doubt finding a Borland version of "high precision library" may also be difficult.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I couldn't get my gcc-mingw to print a long double, but here's code that shows that LARGE numbers work fine with expl():
    Code:
    #include <math.h>
    #include <stdio.h>
    
    void printLongDouble(long double x)
    {
      int e = 0;
      int m = 1;
      int c;
      int i;
    
      if (x < 0) {
          putchar('-');
          x = -x;
      }
      
      if (x > 100000.0) {
        while(x > 1.0) {
          e++;
          x /= 10.0;
        }
      }
      
      while (x < 0.00001) {
          e--;
          x *= 10;
      }
      while(m < x) m *= 10;
      do {
        c = (int)x / m;
        putchar((char)(c+'0'));
        x -= c * m;
        m /= 10;
      } while(x > 1.0);
      if (x) {
        putchar('.');
        m = 1;
        for(i = 0; x && i < 5; i++) {
          x *= 10;
          c = (int)x % 10;
          putchar((char)(c + '0'));
        }
      }
      if (e) 
        {
          if (e >= 0) c = '+'; 
          else { 
    	c = '-'; 
    	e = -e;
          }
          printf("E%c%d",c, e);
        }
      putchar('\n');
    }
    
    int main() {
      long double ld;
      double d;
    
      for(;;) {
        scanf("%lf", &d);
        
        ld = d;
    
        printLongDouble(expl(ld));
      }
      return 0;
    }
    Execution sample:
    Code:
    D:\temp>gcc -Wall exp.c
    
    D:\temp>a
    1000
    0.19700E+435
    9000
    0.44703E+3909
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM