The following minimal example shows the issue:
#include <math.h>
#include <iostream>
int main()
{
double a = log10(1/200);
double b = log10(0.005);
std::cout << "The value of a is " << a << " and b is " << b << std::endl;
}
I compile the program using g++:
g++ -o math math.cpp
./math
The output of the program is:
The value of a is -inf and b is -2.30103
The same thing occurs with C:
#include <math.h>
#include <stdio.h>
int main()
{
double a = log10(1/200);
double b = log10(0.005);
printf("The value of a is %f and b is %f\n", a, b);
}
I compile the program using gcc:
gcc -o math math.c -lm
./math
The output is again:
The value of a is -inf and b is -2.301030
The answer in both cases should be -2.30103. Can someone explain to me what is going on?