Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: add floating-point-annotation and mul-vs-div to style guide #2705

Merged
merged 1 commit into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions dev/source/docs/style-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,36 @@ The user field helps to categorize and hide advanced parameters from being adjus

- Standard - Available to anyone
- Advanced - Available to advanced users

Floating Point Annotation
=========================

ArduPilot is compiled with ``-fsingle-precision-constant``.

That means it is currently allowable to leave off the float specifier from constants. It is also permissable to have them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather say : please use them ... otherwise when we will actually need double we will have issues !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, it makes the code harder to read


**Right**

::

1.0f
1.0

Multiplication vs Division
==========================

Use multiplication rather than division where possible:

**Right**

::

const float foo_m = foo_cm * 0.01;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.01f ;-P


**Wrong**

::

const float foo_m = foo_cm / 100;

Multiplications typically take fewer cycles to compute than divisions.