/****************************************************************************
	Kalkulon - A programmable calculator for programmers

	This file is part of the Kalkulon core.
	
	If you find this source code useful, your are encouraged to use it in your own projects.
	Please give me credit!

	COPYRIGHT by Juergen Holetzeck 2003 - 2008
	e-mail:		contact@kalkulon.de
	homepage:	www.kalkulon.de
****************************************************************************/


// math1.cpp: Implementierung der Klasse math1.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <math.h>
#include <time.h>
#include "math1.h"

//////////////////////////////////////////////////////////////////////
// constants
namespace Kalkulon{
namespace math{
	static const double log2 = log((double)2);
}}

// functions
double Kalkulon::math::fp(double d)
{
	double n;
	return modf( d, &n );     
}


double Kalkulon::math::ip(double d)
{
	double n;
	modf( d, &n );
	return n;     
}


double Kalkulon::math::ld(double d)
{
	return log(d)/log2;
}


double Kalkulon::math::min(double x, double y)
{
	return (x<y?x:y);
}


double Kalkulon::math::max(double x, double y)
{
	return (x>y?x:y);
}


double Kalkulon::math::rand()
{
	return ((double)::rand())/RAND_MAX;
}


double Kalkulon::math::sign(double x)
{
	if(x>0)
		return 1;
	else
		if(x)
			return -1;
		else
			return 0;
}


double Kalkulon::math::srand()
{
	::srand( (unsigned)time( NULL ) );
	return 0;
}
