Show misc_math.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* $Id: misc_math.h,v 1.7 2005/08/26 05:33:25 girod Exp $ */
/**
* \file misc_math.h
* \brief various useful math functions
*
*/
#ifndef __MISC_MATH_H__
#define __MISC_MATH_H__
int exponential_roundup(int size);
static inline float sqrf(float f) { return (f*f); }
static inline int sgnf(float x)
{ return x < 0 ? -1 : (x > 0 ? +1 : 0); }
static inline int sgni(int x)
{ return x < 0 ? -1 : (x > 0 ? +1 : 0); }
/*
* 32.32 fixed point math functions..
*/
typedef int64_t fix_32_32_t;
#define FIX_CONST(n,d) (((((int64_t)n)<<48)/(((int64_t)d)<<16)))
fix_32_32_t fix_div_ff(fix_32_32_t x, fix_32_32_t y);
fix_32_32_t fix_div_sf(fix_32_32_t x, fix_32_32_t y);
fix_32_32_t fix_mult_ff(fix_32_32_t x, fix_32_32_t y);
fix_32_32_t fix_mult_ss(fix_32_32_t x, fix_32_32_t y);
fix_32_32_t fix_mult_if(int64_t x, fix_32_32_t y);
int64_t fix2int(fix_32_32_t x);
fix_32_32_t int2fix(int64_t x);
double fix2double(fix_32_32_t x);
#endif /* __MISC_MATH_H__ */
See more files for this project here