Ad

Windows/Visual Studio Going Wonky On A Perfectly Fine C Program

Okay, no ego, maybe something is funny in the program, but GCC and Clang are compiling it fine and running it just as intended on Ubuntu 20.04 and MacOS 10.14 . Visual Studio 2013 on Win 7 ? Thats a different story.

    #include <stdio.h>
    #include <math.h>

    int main()
    {   double num1, num2, result; 
        printf("\nEnter numbers : ");
        scanf("%lf %lf", &num1, &num2);
        result = pow(num1,num2);
        printf("\n%s %lf\n","Result = ",result);
   }

Cool ? On Mac/Linux When i try 128^128 , I get the accurate answer 528294531135665246352339784916516606518847326036121522127960709026673902556724859474417255887657187894674394993257128678882347559502685537250538978462939576908386683999005084168731517676426441053024232908211188404148028292751561738838396898767036476489538580897737998336.000000

When compiled without errors or warnings in V.S.2013, and run on the same machine (Win7Pro) i get :

52829453113566525 followed by many zeroes such that the answer has the same number of digits as the above answer.

I can verify its the same code, i'm using the same .c file across these platforms, the only variables i see are the compiler and the OS. Is there anything a little developer like me can do to fix Microsoft's mess (as it appears to be) ??

Note : All Operating systems are 64-bit.

Edit : This is a minimal reproducible example from a larger project, MathHack, which is available @ sites.google.com/view/mathhack The full source code is available on that website , although i doubt there's an issue with the rest of the code.

Edit 2 : Screenshots -

Working on MacOSX 10.14 --

https://drive.google.com/file/d/1I0T75vJAUPnbK8y-oCkl_rHSqLTvCWzv/view?usp=sharing

Not Working on Win7 SP2 --

https://drive.google.com/file/d/148EuhwYlrWRom4fIPT_wfkxdSIYya3ep/view?usp=sharing

Edit 3:

Perhaps this is a bug in printf() implementation by Microsoft. Shucks. I'll be upgrading to the latest VS to see if that fixes this.

Ad

Answer

This appears to be a bug in VS 2013's compiler's printf() implementation.

As suggested by @P__J__ I installed VS 2019 Community and that has solved the problem. Thanks, P__J__ .

There seems to be no hope for such issues except to just suck it up and move to the latest VS.

Ad
source: stackoverflow.com
Ad