view Math.h @ 1166:11cda4934da3

font cleaning
author Gloval
date Tue, 04 Jun 2013 08:28:20 +0400
parents 71ba92960bc5
children 0d6c7ff3cddd
line wrap: on
line source

#pragma once
#include <cassert>
#include <limits>
#include <float.h>


/*  186 */
#pragma pack(push, 1)
struct stru193_math
{
  stru193_math();
  int Cos(int angle);
  unsigned int Atan2(int x, int y);
  int Sin(int angle);

  int pTanTable[520];
  int pCosTable[520];
  int pInvCosTable[520];
  unsigned int uIntegerPi;
  unsigned int uIntegerHalfPi;
  unsigned int uIntegerDoublePi;
  unsigned int uDoublePiMask;
  unsigned int uPiMask;
  unsigned int uHalfPiMask;
};
#pragma pack(pop)


int fixpoint_sub0(int, int);
int fixpoint_div(int, int);
int fixpoint_mul(int, int);
int fixpoint_from_float(float value);

#ifndef ROUNDING_EPSILON
#define ROUNDING_EPSILON 0.0000001
#endif

#include <cmath>
#include <cstdlib>
#include <ciso646>

template <typename FloatType>
int bankersRounding(
  const FloatType& value
  ) {
    assert("Method unsupported for this type" && false);
    return value;
}

template<> static int bankersRounding<float>(const float& inValue)
{
  union Cast
  {
    double d;
    long l;
  };
  volatile Cast c;
  c.d = inValue + 6755399441055744.0;
  return c.l;
}

#pragma push_macro("max")
#undef max

template<> static int bankersRounding<double>(const double& inValue)
{
  double maxValue = std::numeric_limits<int>::max();
  assert(maxValue - 6755399441055744.0 >= inValue);
  union Cast
  {
    double d;
    long l;
  };
  volatile Cast c;
  c.d = inValue + 6755399441055744.0;
  return c.l;
}


#pragma pop_macro("max")

extern struct stru193_math *stru_5C6E00;