// AT_UTLS.H
// utility functions

#ifndef AT_UTILS_H
#define AT_UTILS_H

#include <math.h>
#include <time.h>

#include "at_types.h"

//standard rounding
//rounding function
typedef double RealValue;
inline RealValue std_round( RealValue ArVal, uint AuiSpecPrec )
{
	RealValue resultmult = 1.0;
  
  if( ArVal < 0.0 )
  {
    ArVal = fabs( ArVal );
    resultmult = -1.0;
  }
  
  if (!AuiSpecPrec)
    AuiSpecPrec = 1;

  return (floor( (ArVal * AuiSpecPrec) + 0.5 ) / AuiSpecPrec) * resultmult;
};

inline byte * get_time
  (byte *buf,
   uint buf_size,
   byte *format)
{
  time_t timer;
  struct tm *today;

  time(&timer);
  today = localtime(&timer);

  strftime((char*)buf, buf_size, (char*)format, today );

  return buf;
};

inline byte * get_time_t
  (time_t t,
   byte *buf,
   uint buf_size,
   byte *format)
{
  struct tm *today;

  today = localtime(&t);

  strftime((char*)buf, buf_size, (char*)format, today );

  return buf;
};

#endif
 