// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.

#ifndef tools_mathf
#define tools_mathf

namespace tools {

//have : static const fpi = (float)3.1415926535897931160E0; ???

inline float fpi()      {return (float)3.1415926535897931160E0;}
inline float ftwo_pi()  {return (float)6.2831853071795862320E0;}
inline float fhalf_pi() {return (float)1.5707963267948965580E0;}

inline float fdeg2rad() {
  static const float s_v = fpi()/180.0f; //0.0174f
  return s_v;
}
inline float frad2deg() {
  static const float s_v = 180.0f/fpi();
  return s_v;
}

inline int fround(const float& a_x) {
  // From CoinGL/src/base/SbViewportRegion.cpp.
  if (a_x == (float) (int(a_x))) return int(a_x);
  else return (a_x>0.0f) ? int(a_x+0.5f) : -int(0.5f-a_x);
}

}


#include <cmath>

namespace tools {

inline float fcos(const float& x) {return (float)::cos(double(x));}
inline float fsin(const float& x) {return (float)::sin(double(x));}
inline float ftan(const float& x) {return (float)::tan(double(x));}
inline float fpow(const float& x,const float& y) {return (float)::pow(double(x),(double)(y));}
inline float flog10(const float& x) {return (float)::log10(double(x));}
inline float ffloor(const float& x) {return (float)::floor(double(x));}
inline float fceil(const float& x) {return (float)::ceil(double(x));}
inline float ffabs(const float& x) {return (float)::fabs(double(x));}

}

#endif
