fabs and abs, what’s the difference?

(Edit: For a full explaination visit this page http://wp.me/pDfud-X)

abs and fabs are used to get the absolute value of a primitve in C++. Usually int for abs and double or float for fabs.

For some sort of a bright reason I only used abs for all my primitives, including floating points primitves. The strange thing is that on the PC version it worked but on the Android version, which use the exact same code(so there won’t be duplicates of logic files), it didn’t work.

I don’t know how it worked on the PC so well, but on the Android I was getting back ints when doing abs on double, which caused a lot of calculation errors.

I think my PC version might have used an abs that returns a double and not int. Maybe related to some kind of library shenanigens. I will try to research it and make a more educated post in the future, so this post is mainly a note for myself and a warnning for anyone reckless enough to make the same mistake.

 

(Edit: For a full explaination visit this page http://wp.me/pDfud-X)

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