/*********************************************************************
 *                  Flowcode CAL Float File
 *
 * File: AVR_CAL_Float.c
 *
 * (c) 2011 Matrix Multimedia Ltd.
 * http://www.matrixmultimedia.com
 *
 * Software License Agreement
 *
 * The software supplied herewith by Matrix Multimedia Ltd (the
 * “Company”) for its Flowcode graphical programming language is
 * intended and supplied to you, the Company’s customer, for use
 * solely and exclusively on the Company's products. The software
 * is owned by the Company, and is protected under applicable
 * copyright laws. All rights are reserved. Any use in violation
 * of the foregoing restrictions may subject the user to criminal
 * sanctions under applicable laws, as well as to civil liability
 * for the breach of the terms and conditions of this licence.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Changelog:
 *
 *  date  | by | description
 * -------+----+-----------------------------------------------------
 * 060911 | BR | Created
 * 020312 | BR | Updated to v5.1 CAL Schema
 */





#define flt_add(a, b) ((a) + (b))			  	// Binary arithmetic
#define flt_sub(a, b) ((a) - (b))
#define flt_mul(a, b) ((a) * (b))
#define flt_div(a, b) ((a) / (b))
#define flt_rem(a, b) (fmod((a), (b)))

#define flt_neg(a) (-(a))					  	//Unary arithmetic

#define flt_eq(a, b) ((a) == (b))			  	//Comparisons
#define flt_ne(a, b) ((a) != (b))
#define flt_ge(a, b) ((a) >= (b))
#define flt_gt(a, b) ((a) > (b))
#define flt_le(a, b) ((a) <= (b))
#define flt_lt(a, b) ((a) < (b))

#define flt_toi(a)   ((int)(a))			  		//Assignment
#define flt_fromi(a) ((float)(a))

// Rounding functions - nearest, down, up
#define flt_round(f) ((int)((f) + 0.5))
#define flt_floor(f) ((int)(f))
#define flt_ceil(f)  ((int)(f) + 1)

//static double cbrt(double);
static double asinh(double);
static double acosh(double);
static double atanh(double);
static double fround(double, int);
//static char isinf(float f);

#define float32_sqrt sqrt


// Additional floating-point functions
/*
static double cbrt(double x)
{
	return(pow(x, RECIP3));
}
*/

static double asinh(double x)
{
	return (log(x + sqrt(x * x + 1)));
}

static double acosh(double x)
{
	if (x >= 1)
		return (log(x + sqrt(x * x - 1)));
	else
		return(NAN);
}

static double atanh(double x)
{
	if (fabs(x) < 1)
		return (log((1 + x)/(1 - x)) / 2);
	else
		if (fabs(x) == 1)
			return(INFINITY);
		else
			return(NAN);
}

static double fround(double val, int dp)
{
	double mult;

	mult = pow(10, dp);
	val = (round(val * mult)) / mult;
	return(val);
}

/*
static char isinf(float f)
{
	  char* b;
	  b = (char*)&f;
	  if ((b[0] == 0)   &&
		  (b[1] == 0)   &&
		  (b[2] == 128) &&
		  ((b[3] & 127) == 127))
	  {
			return (255);
	  }
	  return (0);
}
*/
