yarf 0.1
Yet Another RepRap Firmware
src/util/math.h
Go to the documentation of this file.
00001 /*
00002  * math.h
00003  *
00004  * Copyright 2011 Pieter Agten
00005  *
00006  * This file is part of Yarf.
00007  *
00008  * Yarf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Yarf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Yarf.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00030 #ifndef MATH_H
00031 #define MATH_H
00032 
00033 #include <math.h>
00034 #include <stdint.h>
00035 
00043 #define MIN(a,b) ((a)<(b)?(a):(b))
00044 
00052 #define MAX(a,b) ((a)>(b)?(a):(b))
00053 
00060 #define SIGNUM(x) (((x) < 0)?(-1):(1))
00061 
00070 #define BOUNDS(min,x,max)  MAX(min,MIN(x,max))
00071 
00072 
00079 inline float
00080 fsquare(float x)
00081 {
00082   return x * x;
00083 }
00084 
00093 inline unsigned long
00094 lsquare(long x)
00095 {
00096   return x * x; //TODO: pre-convert to unsigned longs?
00097 }
00098 
00105 inline uint32_t
00106 uint16_square(uint16_t x)
00107 {
00108   return (uint32_t)x * x;
00109 }
00110 
00111 
00112 #endif //MATH_H
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines