c - Replace floating point math with integer in sigmoid transfer function -


i replace floating point math in these function without losing precision, because have no fpu. possible? think 3 numbers after comma enough.

inline float smaller_f(float value, float bias) {   return value < bias ? value : bias; }  inline float pow2_f(float fval) {   return fval * fval; }  float sigm_f(float fx, float fslope) {   float fval = (180.f - smaller_f(fabs(fslope * fx), 179.9f) ) / 180.f;   return fval / sqrt(1.f + pow2_f(fval) ); } 

a fixed-point math library need. preferred solution anthony williams' fixed-point math c++ library. because in c++ , defines fixed class extensive function , operator overloading, can largely used replacing float or double in existing code fixed. uses int64_t underlying integer data type, 34 integer bits , 28 fractional bits (34q28), 8 decimal places , wider range int32_t.

if compiler supports c++, can still write code using c subset if prefer, using c++ support library.

on 32bit arm library performs 5 times faster software-floating point , comparable in performance arm's vfp unit c code.

note sqrt() function in library has poor precision performance small values looses lower-order bits in intermediate calculations can preserved. can improved replacing code version presented in this question.

there no doubt c libraries fixed-point math lack simplicity , convenience of "real" fixed-point data type provided library, , library has complete set of standard library math function equivalents, while many fixed point solutions provide basic arithmetic operators.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -