Menu

#615 pow() function problem

open
nobody
None
5
2012-09-26
2005-12-27
Anonymous
No

I compiled the following program and executed it.

include <stdio.h>

include <math.h>

int main(void){
int i;

for(i = 0; i <= 8; i++){
printf("pow(10, %d) :%d\n", i, int(pow(10, i)));
printf("powf(10, %d):%d\n", i, int(powf(10, i)));
printf("powl(10, %d):%d\n", i, int(powl(10, i)));
};

getchar();
return 0;
};

Then the result is....

pow(10, 0) :1
powf(10, 0):1
powl(10, 0):1
pow(10, 1) :10
powf(10, 1):10
powl(10, 1):10
pow(10, 2) :99
powf(10, 2):100
powl(10, 2):100
pow(10, 3) :1000
powf(10, 3):1000
powl(10, 3):1000
pow(10, 4) :9999
powf(10, 4):10000
powl(10, 4):10000
pow(10, 5) :100000
powf(10, 5):100000
powl(10, 5):100000
pow(10, 6) :1000000
powf(10, 6):1000000
powl(10, 6):1000000
pow(10, 7) :10000000
powf(10, 7):10000000
powl(10, 7):10000000
pow(10, 8) :99999999
powf(10, 8):100000000
powl(10, 8):100000000

It seems a bug

My environment:
AMD Althon Thunderbird 900 Mhz
256 Mb PC-133 SDRAM
Microsoft Windows XP with Service Pack 2
Dev-C++ 5 beta 4992

Discussion

  • Michele Tartara

    Michele Tartara - 2007-11-09

    Logged In: YES
    user_id=1072056
    Originator: NO

    Using Dev-C++ 5 beta 4.9.9.2 the pow() function also fails on other inputs:
    pow(5,4)=624
    pow(10,4)=9999
    pow(5,2)=24
    pow(10,2)=99

    It mostly seems to fail when the base is divisible by 5.

     
  • Nobody/Anonymous

    Logged In: NO

    int i=5,j;

    j=++i++i++i;
    printf("%d\n",i);
    printf("%d",j);

    this value should be 336, but it's 392.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.