I have some experience in Defence & Aerospace industry. I am mostly interested in swarm robotics. I like to write about C++ language features and best practices.
I compared its speed to the default C++ abs from math.h like…
Use floating numbers for division, unless you intentionally want to lose the decimal part.
It is a good idea to write functions and call these functions from main. I understand that you are writing simple programs but writing functions prepares you for the more complex stuff you will face later on.
Don't lose your motivation and try to learn new things everyday. Have a good one!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Ali,
I have a few comments, hope it helps:
Prefer cmath::abs to writing your own absolute number function. Related question:
I am currently writing some glsl like vector math classes in C++, and I just implemented an
abs()function like this:I compared its speed to the default C++
absfrommath.hlike…Use floating numbers for division, unless you intentionally want to lose the decimal part.
It is a good idea to write functions and call these functions from main. I understand that you are writing simple programs but writing functions prepares you for the more complex stuff you will face later on.
Don't lose your motivation and try to learn new things everyday. Have a good one!