c++ - How to set returned value of log10(0)? -


it prints me -inf. fixed every library/compiler i'll use?

code:

#include <iostream> #include <math.h>  using namespace std;  int main () {   double result = log10(0.0);   cout << result; } 

or change in different platforms? how manage pole error keeping double?

according cplusplus, depends on library log10(0). however, in general value of log10(0) not defined (can -inf if like, not real number). usually, should prevent such undefined results (not undefined in c++ sense of undefined behaviour, in mathematical sense) before happen. e.g.

double x; x = foo(); if ( x <= 0 ) {     /* handle case */ else {     y = log10(x); } 

what value use in case of log10(0) depends on application. however, think easier check 0 before doing calculation instead of relying on log10(0) returning particular value (as might -inf or different).


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -