// ------------------------------------------------------------------------
// ON Semiconductor Proprietary and Confidential Information.
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// Company           : ON Semiconductor
// ------------------------------------------------------------------------
// File              : $RCSfile: libmath.c,v $
// ------------------------------------------------------------------------
// Last Modified     : $Date: 2016/04/01 08:03:44 $
// Last Modified By  : $Author: fg7g4t $
// Revision          : $Revision: 1.1 $
// ------------------------------------------------------------------------
// Description       : C file with functions which can be imported to SV
// ------------------------------------------------------------------------
// Revision history  :
//
//   $Log: libmath.c,v $
//   Revision 1.1  2016/04/01 08:03:44  fg7g4t
//   Initial revision (directory structure & standard scripts revision 255).
//

#include "svdpi.h"

// since we are using math functions, include the math library
// #include          

// can use io_printf() instead of printf() to put into ncsim.log file
const double c_PI = 3.141592653589793238462643383276;


//   import "DPI-C" context get_real_c = function real get_real_v ();
double get_real_c() {  // imported SV function
  // exercise DPI function - get calling scope
  printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );
  return c_PI;
}

 
//   import "DPI-C" context put_real_c = function void put_real_v (real x);      
void put_real_c(double n) {  // imported SV function
  // exercise DPI function - get calling scope
  printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );
  printf("pi + 5.0 = %f\n", n+5.0);       
}

//   import "DPI-C" context get_pi = function real get_pi ();
// // real_pi = get_pi();
double get_pi() {  // imported SV function
  return c_PI;
}

//    import "DPI-C" context sv_sin = function real sv_sin (real x); 
// // real_sin = sv_sin(real angle_in_degrees);
double sv_sin(double angle) {
  return sin(angle/180*c_PI);
}

//    import "DPI-C" context sv_cos = function real sv_cos (real x); 
// // real_cos = sv_cos(real angle_in_degrees);
double sv_cos(double angle) {
  return cos(angle/180*c_PI);
}

//    import "DPI-C" context sv_tan = function real sv_tan (real x); 
// // real_tan = sv_tan(real angle_in_degrees);
double sv_tan(double angle) {
  return tan(angle/180*c_PI);
}

//    import "DPI-C" context sv_asin = function real sv_asin (real x); 
// // real_asin = sv_asin(real val);
double sv_asin(double val) {
  return asin(val)*180/c_PI;
}

//    import "DPI-C" context sv_acos = function real sv_acos (real x); 
// // real_acos = sv_acos(real val);
double sv_acos(double val) {
  return acos(val)*180/c_PI;
}

//    import "DPI-C" context sv_atan = function real sv_atan (real x); 
// // real_atan = sv_atan(real val);
double sv_atan(double val) {
  return atan(val)*180/c_PI;
}

//    import "DPI-C" context sv_log = function real sv_log (real x); 
// // real_log = sv_log(real number);
double sv_log(double val) {
  return log(val);
}

//    import "DPI-C" context sv_log10 = function real sv_log10 (real x); 
// // real_log10 = sv_log10(real number);
double sv_log10(double val) {
  return log10(val);
}

//    import "DPI-C" context sv_exp = function real sv_exp (real x); 
// // real_exp = sv_exp(real number);
double sv_exp(double val) {
  return exp(val);
}

//    import "DPI-C" context sv_sqrt = function real sv_sqrt (real x); 
// // real_sqrt = sv_sqrt(real number);
double sv_sqrt(double val) {
  return sqrt(val);
}

//    import "DPI-C" context sv_pow = function real sv_pow (real base, power); 
// // real_pow = sv_pow(real base, power);
double sv_pow(double base, double power) {
  return pow(base, power);
}

