Pharap / FixedPointsArduino

A fixed point arithmetic library for Arduino
Apache License 2.0
84 stars 9 forks source link
arduino arithmetic fixed-point fixed-points header-only library maths

FixedPoints

A portable fixed point arithmetic library.

Some knowledge of how fixed point types are formatted is required to used this library to full effect. No knowledge of how these operations are implemented is required to use them.

This library was written with Arduino in mind, as well as CPUs with limited floating point support. However, given the templated nature of the library, it should still function on a wide variety of CPUs.

Project Showcase

Here's a list of projects that use FixedPoints:

If you have a project that uses FixedPoints and would like your work to be showcased here, please raise an issue.

Requirements:

Licence

This code uses the Apache 2.0 Licence. This means:

Conditional Compilation

These are symbols you can define prior to library inclusion to alter the behaviour of the library.

FAQ

Contents

This library supplies two core types and sixteen type aliases.

Defines

Core Types:

The core types are provided by FixedPoints.h.

Aliases:

The common aliases are provided by FixedPointsCommon.h.

(About Q Format.)

Operators:

Free Functions:

Member Functions:

Static Functions:

Construction:

Note that both UFixed<I, F> and SFixed<I, F> are implicitly compile-time constructable from all integer and decimal literals. This means that you may write code such as UFixed<8, 8> value = 0.5; without incurring a runtime cost for converting from double to UFixed<8, 8> because the constructor is constexpr.

UFixed<I, F> is constructable from:

SFixed<I, F> is constructable from:

Casts:

UFixed<I, F> is explicitly convertible to:

SFixed<I, F> is explicitly convertible to: