Use fabs for getting the absolute from double

I am porting my Octave code to C++, somehow I always got zero for one expression that I calculate. After debugging, it turns out after I take abs(expression), the values always zero. Argh. I forgot, abs() in C++ is only for integer and long. I need to use fabs() for float or double. Now it works just fine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: