/////////////////////////////////////////////////////////////////////////////
// fun.cc
//
// SIMLIB version: 2.18
// Date: 2004-01-25
//
// Copyright (c) 1991-2004 Petr Peringer 
//
// This library is licensed under GNU Library GPL. See the file COPYING.
//

//
// standard continuous function blocks
//


////////////////////////////////////////////////////////////////////////////
// interface
//

#include "simlib.h"
#include "internal.h"

#include <cmath>          // functions

////////////////////////////////////////////////////////////////////////////
// implementation
//

SIMLIB_IMPLEMENTATION

////////////////////////////////////////////////////////////////////////////
// class Function implementation - functions with one argument
//
Function::Function(Input i, double (*pf)(double)) : aContiBlock1(i), f(pf) {
  // add check !!! ### ??? what
  dprintf(("Function::Function(in)"));
}

double Function::Value() {
  // test Loop
  double ret = f(InputValue());
  //
  return ret;
}

////////////////////////////////////////////////////////////////////////////
// class Function2 implementation - functions with two arguments
//
Function2::Function2(Input i1, Input i2, double (*pf)(double,double))
  : aContiBlock2(i1,i2), f(pf) {
  // add check !!! ###
  dprintf(("Function2::Function2(in,in)"));
}

double Function2::Value() {
  // test Loop
  double ret = f(Input1Value(), Input2Value());
  //
  return ret;
}


////////////////////////////////////////////////////////////////////////////
// SIMLIB local definitions:
//

static double sign(double x)
{
  if( x==0.0 )  return 0.0;
  if( x>0.0 )   return 1.0;
  else          return -1.0;
}


////////////////////////////////////////////////////////////////////////////
// SIMLIB block functions
//

Input Abs(Input x)              { return new Function(x, fabs); }

Input Sin(Input x)              { return new Function(x, sin); }
Input Cos(Input x)              { return new Function(x, cos); }
Input Tan(Input x)              { return new Function(x, tan); }

Input ASin(Input x)             { return new Function(x, asin); }
Input ACos(Input x)             { return new Function(x, acos); }
Input ATan(Input x)             { return new Function(x, atan); }
Input ATan2(Input y, Input x)   { return new Function2(y, x, atan2); }

Input Exp(Input x)              { return new Function(x, exp); }
Input Log10(Input x)            { return new Function(x, log10); }
Input Ln(Input x)               { return new Function(x, log); }
Input Pow(Input x, Input y)     { return new Function2(x, y, pow); }

Input Sign(Input x)             { return new Function(x, sign); }

Input Sqrt(Input x)             { return new Function(x, sqrt); }

Input Min(Input x, Input y)     { return new Function2(x, y, min); }
Input Max(Input x, Input y)     { return new Function2(x, y, max); }


////////////////////////////////////////////////////////////////////////////
// end of FUN.CPP
////////////////////////////////////////////////////////////////////////////



syntax highlighted by Code2HTML, v. 0.9.1