COSA
An Object-Oriented Platform for Arduino Programming
Math.hh File Reference
#include <math.h>
#include "Cosa/Types.h"
Include dependency graph for Math.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint16_t rand (uint16_t range)
 
int16_t rand (int16_t low, int16_t high)
 
uint32_t random (uint32_t range)
 
int32_t random (int32_t low, int32_t high)
 
template<class T >
uint8_t log2 (T value)
 
template<class T , T in_min, T in_max, T out_min, T out_max>
map (T x)
 
template<class T , T low, T high>
constrain (T x)
 
template<class T , T low, T high>
bool is_within (T x)
 

Detailed Description

Version
1.0

License

Copyright (C) 2014-2015, Mikael Patel.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

This file is part of the Arduino Che Cosa project.

Definition in file Math.hh.

Function Documentation

template<class T , T low, T high>
T constrain ( x)

Template constrain function for given class/data type.

Parameters
[in]Tclass value to constrain.
[in]xvalue to constrain.
[in]lowminimum value.
[in]highmaximum value.
Returns
constrain

Definition at line 126 of file Math.hh.

template<class T , T low, T high>
bool is_within ( x)

Template within range check function for given class/data type.

Parameters
[in]Tclass value check range.
[in]xvalue to check.
[in]lowminimum range value.
[in]highmaximum range value.
Returns
bool

Definition at line 142 of file Math.hh.

template<class T >
uint8_t log2 ( value)
inline

Calculate log(2) of the given value. The given template parameter type should be unsigned.

Parameters
[in]Tunsigned integer type (uint8_t, uint16_t,..)
[in]value
Returns
log(2) > value

Definition at line 85 of file Math.hh.

template<class T , T in_min, T in_max, T out_min, T out_max>
T map ( x)

Template map function for given class/data type.

Parameters
[in]Tclass value to map.
[in]xvalue to map.
[in]in_minminimum value in input range.
[in]in_maxmaximum value in input range.
[in]out_minminimum value in output range.
[in]out_maxmaximum value in output range.
Returns
mapping

Definition at line 106 of file Math.hh.

uint16_t rand ( uint16_t  range)
inline

Random number in given range (0..range). Max range value is RAND_MAX(0x7fff) - 1.

Parameters
[in]rangevalue.
Returns
random number.

Definition at line 34 of file Math.hh.

int16_t rand ( int16_t  low,
int16_t  high 
)
inline

Random number in given range (low..high). Max high value is RAND_MAX(0x7fff).

Parameters
[in]lowrange value.
[in]highrange value.
Returns
random number.

Definition at line 47 of file Math.hh.

uint32_t random ( uint32_t  range)
inline

Random number in given range (0..range-1). Max range value is RANDOM_MAX(0x7fffffffL).

Parameters
[in]rangevalue.
Returns
random number.

Definition at line 59 of file Math.hh.

int32_t random ( int32_t  low,
int32_t  high 
)
inline

Random number in given range (low..high-1). Max high value is RANDOM_MAX(0x7fffffff).

Parameters
[in]lowrange value.
[in]highrange value.
Returns
random number.

Definition at line 72 of file Math.hh.