inline auto waveshaper_tanh(E1&& input, double saturation) { return tanh(saturation * input) * (coth(saturation)); }

static int math_tanh (lua_State *L) { lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); return 1; }

long double tanhl(long double x) { return tanh((double) x); }

Real DT_FTIME() { // return 0.0; return rT*(1-pow(tanh(rT*TIME),2)); }

int PY_Macro2D::update(void) { Domain *theDomain=this->getDomain(); Tt = theDomain->getCurrentTime(); double dt = Tt - Ct; // determine the strain const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); double Ru = disp1(1); // pore water pressure // Use displacements to find the total strain in the element TU = 0.0; for (int i=0; i<2; i++) { TU -= (disp2(i)-disp1(i)) * trans(0,i); } // Find the change in strain double dU = TU - CU; // Declare the other variables required double dz, f, f_, Tzold, Tznew; dz = K/py*(1-(tanh(a*abs(Cz))/tanh(a))*(b+g*signum(dU*Cz)))*dU; Tz = Cz+dz; // Pore Pressure Generation Model Tforce = py*Tz*CS; Ttangent = K*(1-(tanh(a*fabs(Tz))/tanh(a))*(b+g*signum(dU*Tz)))*TS; TW = CW; double dSb = 0.0; if (fabs(Tz) <= 0.67*m2/m1) { TW = CW+fabs(Tforce*dU)/py/(py/K); dSb = exp(-1*pow(TW/w1,1.4))*1.4*pow(TW/w1,0.4)*fabs(Tforce*dU)/py/(py/K)/w1; } double Sff = 1-Ru; double dSd = beta/(0.01+0.99*fabs(Sff-CS0))*pow(CS,p1) *dt/(1+beta/(0.01+0.99*fabs(Sff-CS0))*pow(CS,p1) *dt)*(Sff-CS); TS0 = CS0 - dSb + dSd; if (fabs(Tz) <= 0.67*m2/m1) { TS = TS0; } else { double alp = 0.67*m2/m1; TS = TS0*(1+alp*alp)/(fabs(Tz)*alp+pow((Tz*alp)*(Tz*alp)+(1-Tz*Tz)*(1+alp*alp),0.5)); } // Compute force and tangent // Tforce = py*Tz*TS; // Ttangent = K*(1-(tanh(a*fabs(Tz))/tanh(a))*(b+g*signum(dU*Tz)))*TS; return 0; }

PetscInt main(PetscInt argc,char **args) { typedef enum {RANDOM, CONSTANT, TANH, NUM_FUNCS} FuncType; const char *funcNames[NUM_FUNCS] = {"random", "constant", "tanh"}; Mat A, AA; PetscMPIInt size; PetscInt N,i, stencil=1,dof=3; PetscInt dim[3] = {10,10,10}, ndim = 3; Vec coords,x,y,z,xx, yy, zz; Vec xxsplit[DOF], yysplit[DOF], zzsplit[DOF]; PetscReal h[3]; PetscScalar s; PetscRandom rdm; PetscReal norm, enorm; PetscInt func; FuncType function = TANH; DM da, da1, coordsda; PetscBool view_x = PETSC_FALSE, view_y = PETSC_FALSE, view_z = PETSC_FALSE; PetscErrorCode ierr; ierr = PetscInitialize(&argc,&args,(char *)0,help);CHKERRQ(ierr); #if !defined(PETSC_USE_COMPLEX) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This example requires complex numbers"); #endif ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size);CHKERRQ(ierr); if (size != 1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This is a uniprocessor example only!"); ierr = PetscOptionsBegin(PETSC_COMM_WORLD, PETSC_NULL, "USFFT Options", "ex27");CHKERRQ(ierr); ierr = PetscOptionsEList("-function", "Function type", "ex27", funcNames, NUM_FUNCS, funcNames[function], &func, PETSC_NULL);CHKERRQ(ierr); function = (FuncType) func; ierr = PetscOptionsEnd();CHKERRQ(ierr); ierr = PetscOptionsGetBool(PETSC_NULL,"-view_x",&view_x,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsGetBool(PETSC_NULL,"-view_y",&view_y,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsGetBool(PETSC_NULL,"-view_z",&view_z,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsGetIntArray(PETSC_NULL,"-dim",dim,&ndim,PETSC_NULL);CHKERRQ(ierr); // DMDA with the correct fiber dimension ierr = DMDACreate3d(PETSC_COMM_SELF,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR, dim[0], dim[1], dim[2], PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof, stencil, PETSC_NULL, PETSC_NULL, PETSC_NULL, &da); CHKERRQ(ierr); // DMDA with fiber dimension 1 for split fields ierr = DMDACreate3d(PETSC_COMM_SELF,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR, dim[0], dim[1], dim[2], PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 1, stencil, PETSC_NULL, PETSC_NULL, PETSC_NULL, &da1); CHKERRQ(ierr); // Coordinates ierr = DMDAGetCoordinateDA(da, &coordsda); ierr = DMGetGlobalVector(coordsda, &coords);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) coords, "Grid coordinates");CHKERRQ(ierr); for(i = 0, N = 1; i < 3; i++) { h[i] = 1.0/dim[i]; PetscScalar *a; ierr = VecGetArray(coords, &a);CHKERRQ(ierr); PetscInt j,k,n = 0; for(i = 0; i < 3; ++i) { for(j = 0; j < dim[i]; ++j){ for(k = 0; k < 3; ++k) { a[n] = j*h[i]; // coordinate along the j-th point in the i-th dimension ++n; } } } ierr = VecRestoreArray(coords, &a);CHKERRQ(ierr); } ierr = DMDASetCoordinates(da, coords);CHKERRQ(ierr); ierr = VecDestroy(&coords);CHKERRQ(ierr); // Work vectors ierr = DMGetGlobalVector(da, &x);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) x, "Real space vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da, &xx);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) xx, "Real space vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da, &y);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) y, "USFFT frequency space vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da, &yy);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) yy, "FFTW frequency space vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da, &z);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) z, "USFFT reconstructed vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da, &zz);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) zz, "FFTW reconstructed vector");CHKERRQ(ierr); // Split vectors for FFTW for(int ii = 0; ii < 3; ++ii) { ierr = DMGetGlobalVector(da1, &xxsplit[ii]);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) xxsplit[ii], "Real space split vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da1, &yysplit[ii]);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) yysplit[ii], "FFTW frequency space split vector");CHKERRQ(ierr); ierr = DMGetGlobalVector(da1, &zzsplit[ii]);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) zzsplit[ii], "FFTW reconstructed split vector");CHKERRQ(ierr); } ierr = PetscPrintf(PETSC_COMM_SELF, "%3-D: USFFT on vector of ");CHKERRQ(ierr); for(i = 0, N = 1; i < 3; i++) { ierr = PetscPrintf(PETSC_COMM_SELF, "dim[%d] = %d ",i,dim[i]);CHKERRQ(ierr); N *= dim[i]; } ierr = PetscPrintf(PETSC_COMM_SELF, "; total size %d \n",N);CHKERRQ(ierr); if (function == RANDOM) { ierr = PetscRandomCreate(PETSC_COMM_SELF, &rdm);CHKERRQ(ierr); ierr = PetscRandomSetFromOptions(rdm);CHKERRQ(ierr); ierr = VecSetRandom(x, rdm);CHKERRQ(ierr); ierr = PetscRandomDestroy(&rdm);CHKERRQ(ierr); } else if (function == CONSTANT) { ierr = VecSet(x, 1.0);CHKERRQ(ierr); } else if (function == TANH) { PetscScalar *a; ierr = VecGetArray(x, &a);CHKERRQ(ierr); PetscInt j,k = 0; for(i = 0; i < 3; ++i) { for(j = 0; j < dim[i]; ++j) { a[k] = tanh((j - dim[i]/2.0)*(10.0/dim[i])); ++k; } } ierr = VecRestoreArray(x, &a);CHKERRQ(ierr); } if(view_x) { ierr = VecView(x, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); } ierr = VecCopy(x,xx);CHKERRQ(ierr); // Split xx ierr = VecStrideGatherAll(xx,xxsplit, INSERT_VALUES);CHKERRQ(ierr); //YES! 'Gather' means 'split' (or maybe 'scatter'?)! ierr = VecNorm(x,NORM_2,&norm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|x|_2 = %g\n",norm);CHKERRQ(ierr); /* create USFFT object */ ierr = MatCreateSeqUSFFT(da,da,&A);CHKERRQ(ierr); /* create FFTW object */ ierr = MatCreateSeqFFTW(PETSC_COMM_SELF,3,dim,&AA);CHKERRQ(ierr); /* apply USFFT and FFTW FORWARD "preemptively", so the fftw_plans can be reused on different vectors */ ierr = MatMult(A,x,z);CHKERRQ(ierr); for(int ii = 0; ii < 3; ++ii) { ierr = MatMult(AA,xxsplit[ii],zzsplit[ii]);CHKERRQ(ierr); } // Now apply USFFT and FFTW forward several (3) times for (i=0; i<3; ++i){ ierr = MatMult(A,x,y);CHKERRQ(ierr); for(int ii = 0; ii < 3; ++ii) { ierr = MatMult(AA,xxsplit[ii],yysplit[ii]);CHKERRQ(ierr); } ierr = MatMultTranspose(A,y,z);CHKERRQ(ierr); for(int ii = 0; ii < 3; ++ii) { ierr = MatMult(AA,yysplit[ii],zzsplit[ii]);CHKERRQ(ierr); } } // Unsplit yy ierr = VecStrideScatterAll(yysplit, yy, INSERT_VALUES);CHKERRQ(ierr); //YES! 'Scatter' means 'collect' (or maybe 'gather'?)! // Unsplit zz ierr = VecStrideScatterAll(zzsplit, zz, INSERT_VALUES);CHKERRQ(ierr); //YES! 'Scatter' means 'collect' (or maybe 'gather'?)! if(view_y) { ierr = PetscPrintf(PETSC_COMM_WORLD, "y = \n");CHKERRQ(ierr); ierr = VecView(y, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD, "yy = \n");CHKERRQ(ierr); ierr = VecView(yy, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); } if(view_z) { ierr = PetscPrintf(PETSC_COMM_WORLD, "z = \n");CHKERRQ(ierr); ierr = VecView(z, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD, "zz = \n");CHKERRQ(ierr); ierr = VecView(zz, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); } /* compare x and z. USFFT computes an unnormalized DFT, thus z = N*x */ s = 1.0/(PetscReal)N; ierr = VecScale(z,s);CHKERRQ(ierr); ierr = VecAXPY(x,-1.0,z);CHKERRQ(ierr); ierr = VecNorm(x,NORM_1,&enorm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|x-z| = %g\n",enorm);CHKERRQ(ierr); /* compare xx and zz. FFTW computes an unnormalized DFT, thus zz = N*x */ s = 1.0/(PetscReal)N; ierr = VecScale(zz,s);CHKERRQ(ierr); ierr = VecAXPY(xx,-1.0,zz);CHKERRQ(ierr); ierr = VecNorm(xx,NORM_1,&enorm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|xx-zz| = %g\n",enorm);CHKERRQ(ierr); /* compare y and yy: USFFT and FFTW results*/ ierr = VecNorm(y,NORM_2,&norm);CHKERRQ(ierr); ierr = VecAXPY(y,-1.0,yy);CHKERRQ(ierr); ierr = VecNorm(y,NORM_1,&enorm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|y|_2 = %g\n",norm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|y-yy| = %g\n",enorm);CHKERRQ(ierr); /* compare z and zz: USFFT and FFTW results*/ ierr = VecNorm(z,NORM_2,&norm);CHKERRQ(ierr); ierr = VecAXPY(z,-1.0,zz);CHKERRQ(ierr); ierr = VecNorm(z,NORM_1,&enorm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|z|_2 = %g\n",norm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF, "|z-zz| = %g\n",enorm);CHKERRQ(ierr); /* free spaces */ ierr = DMRestoreGlobalVector(da,&x);CHKERRQ(ierr); ierr = DMRestoreGlobalVector(da,&xx);CHKERRQ(ierr); ierr = DMRestoreGlobalVector(da,&y);CHKERRQ(ierr); ierr = DMRestoreGlobalVector(da,&yy);CHKERRQ(ierr); ierr = DMRestoreGlobalVector(da,&z);CHKERRQ(ierr); ierr = DMRestoreGlobalVector(da,&zz);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

//----------------------------------------------------------------------- void FunCmplxTanH::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int) { cmplx_type v(a_pArg[0]->GetFloat(), a_pArg[0]->GetImag()); *ret = tanh(v); }

double HHVM_FUNCTION(tanh, double arg) { return tanh(arg); }

/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void evaluate_expr(scicos_block *block, int flag) { static double stack [1000]; static int count = 0, bottom = 0, nzcr = 0, i = 0, phase = 0; int j = 0; if (flag == 1 || flag == 6 || flag == 9) { phase = get_phase_simulation(); bottom = -1; count = -1; nzcr = -1; while (count < block->nipar - 1) { count = count + 1; switch (block->ipar[count]) { case 2: count = count + 1; bottom = bottom + 1; if (bottom > 999) { set_block_error(-16); return; } if (block->nin > 1) { stack[bottom] = block->inptr[block->ipar[count] - 1][0]; } else { j = block->ipar[count] - 1; if (j < block->insz[0]) { stack[bottom] = block->inptr[0][block->ipar[count] - 1]; } else { stack[bottom] = 0.; } } break; case 6: count = count + 1; bottom = bottom + 1; if (bottom > 999) { set_block_error(-16); return; } stack[bottom] = block->rpar[block->ipar[count] - 1]; break; case 5: count = count + 1; /* invalid script : call a function without lhs */ if (bottom < 0) { set_block_error(-2); return; } switch (block->ipar[count]) { case 1: stack[bottom - 1] = stack[bottom - 1] + stack[bottom]; bottom = bottom - 1; break; case 2: stack[bottom - 1] = stack[bottom - 1] - stack[bottom]; bottom = bottom - 1; break; case 3: stack[bottom - 1] = stack[bottom - 1] * stack[bottom]; bottom = bottom - 1; break; case 7: stack[bottom - 1] = stack[bottom - 1] / stack[bottom]; bottom = bottom - 1; break; case 15: stack[bottom - 1] = pow(stack[bottom - 1], stack[bottom]); bottom = bottom - 1; break; case 16: /* case == */ if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] == stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] == stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 17: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] < stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] < stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 18: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] > stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] > stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 19: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] <= stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] <= stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 20: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] >= stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] >= stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 21: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = (stack[bottom - 1] != stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom - 1] != stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 28: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = ((int)stack[bottom - 1] || (int)stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = ((int)stack[bottom - 1] || (int)stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 29: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom - 1] - stack[bottom]; if (phase == 1) { block->mode[nzcr] = ((int)stack[bottom - 1] && (int)stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = ((int)stack[bottom - 1] && (int)stack[bottom]); } else { i = block->mode[nzcr]; } stack[bottom - 1] = (double)i; bottom = bottom - 1; break; case 30: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { block->g[nzcr] = stack[bottom]; if (phase == 1) { block->mode[nzcr] = (0.0 == stack[bottom]); } } if (phase == 1 || block->ng == 0) { i = (stack[bottom] == 0.0); } else { i = block->mode[nzcr]; } if (i) { stack[bottom] = 1.0; } else { stack[bottom] = 0.0; } break; case 99: stack[bottom] = -stack[bottom]; break; case 101: stack[bottom] = sin(stack[bottom]); break; case 102: stack[bottom] = cos(stack[bottom]); break; case 103: stack[bottom] = tan(stack[bottom]); break; case 104: stack[bottom] = exp(stack[bottom]); break; case 105: stack[bottom] = log(stack[bottom]); break; case 106: stack[bottom] = sinh(stack[bottom]); break; case 107: stack[bottom] = cosh(stack[bottom]); break; case 108: stack[bottom] = tanh(stack[bottom]); break; case 109: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] > 0) { i = (int)floor(stack[bottom]); } else { i = (int)ceil(stack[bottom]); } if (i == 0) { block->g[nzcr] = (stack[bottom] - 1) * (stack[bottom] + 1); } else if (i > 0) { block->g[nzcr] = (stack[bottom] - i - 1.) * (stack[bottom] - i); } else { block->g[nzcr] = (stack[bottom] - i) * (stack[bottom] - i + 1); } if (i % 2) { block->g[nzcr] = -block->g[nzcr]; } if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { if (stack[bottom] > 0) { stack[bottom] = floor(stack[bottom]); } else { stack[bottom] = ceil(stack[bottom]); } } else { stack[bottom] = (double) block->mode[nzcr]; } break; /* if (stack[bottom]>0) { stack[bottom]=floor(stack[bottom]); }else{ stack[bottom]=ceil(stack[bottom]); }*/ break; case 110: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] > 0) { i = (int)floor(stack[bottom] + .5); } else { i = (int)ceil(stack[bottom] - .5); } block->g[nzcr] = (stack[bottom] - i - .5) * (stack[bottom] - i + .5); if (i % 2) { block->g[nzcr] = -block->g[nzcr]; } if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { if (stack[bottom] > 0) { stack[bottom] = floor(stack[bottom] + .5); } else { stack[bottom] = ceil(stack[bottom] - .5); } } else { stack[bottom] = (double) block->mode[nzcr]; } break; /* if (stack[bottom]>0) { stack[bottom]=floor(stack[bottom]+.5); }else{ stack[bottom]=ceil(stack[bottom]-.5); }*/ case 111: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { i = (int)ceil(stack[bottom]); block->g[nzcr] = (stack[bottom] - i) * (stack[bottom] - i + 1); if (i % 2) { block->g[nzcr] = -block->g[nzcr]; } if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { stack[bottom] = ceil(stack[bottom]); } else { stack[bottom] = (double) block->mode[nzcr]; } break; case 112: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { i = (int)floor(stack[bottom]); block->g[nzcr] = (stack[bottom] - i - 1) * (stack[bottom] - i); if (i % 2) { block->g[nzcr] = -block->g[nzcr]; } if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { stack[bottom] = floor(stack[bottom]); } else { stack[bottom] = (double) block->mode[nzcr]; } break; case 113: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] > 0) { i = 1; } else if (stack[bottom] < 0) { i = -1; } else { i = 0; } block->g[nzcr] = stack[bottom]; if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { if (stack[bottom] > 0) { stack[bottom] = 1.0; } else if (stack[bottom] < 0) { stack[bottom] = -1.0; } else { stack[bottom] = 0.0; } } else { stack[bottom] = (double) block->mode[nzcr]; } break; /* if (stack[bottom]>0) { stack[bottom]=1.0; }else if(stack[bottom]<0){ stack[bottom]=-1.0; }else{ stack[bottom]=0.0; }*/ case 114: /* abs */ if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] > 0) { i = 1; } else if (stack[bottom] < 0) { i = -1; } else { i = 0; } block->g[nzcr] = stack[bottom]; if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { if (stack[bottom] > 0) { /* stack[bottom] = stack[bottom]; */ } else { stack[bottom] = -stack[bottom]; } } else { stack[bottom] = stack[bottom] * (block->mode[nzcr]); } break; /* if (stack[bottom]>0) { stack[bottom]=stack[bottom]; }else { stack[bottom]=-stack[bottom]; }*/ case 115: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] > stack[bottom - 1]) { i = 0; } else { i = 1; } block->g[nzcr] = stack[bottom] - stack[bottom - 1]; if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { stack[bottom - 1] = Max(stack[bottom - 1], stack[bottom]); } else { stack[bottom - 1] = stack[bottom - block->mode[nzcr]]; } bottom = bottom - 1; break; case 116: if (block->ng > 0) { nzcr = nzcr + 1; } if (flag == 9) { if (stack[bottom] < stack[bottom - 1]) { i = 0; } else { i = 1; } block->g[nzcr] = stack[bottom] - stack[bottom - 1]; if (phase == 1) { block->mode[nzcr] = i; } } if (phase == 1 || block->ng == 0) { stack[bottom - 1] = Min(stack[bottom - 1], stack[bottom]); } else { stack[bottom - 1] = stack[bottom - block->mode[nzcr]]; } bottom = bottom - 1; break; case 117: stack[bottom] = asin(stack[bottom]); break; case 118: stack[bottom] = acos(stack[bottom]); break; case 119: stack[bottom] = atan(stack[bottom]); break; case 120: stack[bottom] = asinh(stack[bottom]); break; case 121: stack[bottom] = acosh(stack[bottom]); break; case 122: stack[bottom] = atanh(stack[bottom]); break; case 123: stack[bottom - 1] = atan2(stack[bottom - 1], stack[bottom]); bottom = bottom - 1; break; case 124: stack[bottom] = log10(stack[bottom]); break; } } } #if _MSC_VER if (!_finite(stack[bottom]) || _isnan(stack[bottom])) { #else if (isinf(stack[bottom]) || isnan(stack[bottom])) { #endif if (flag == 6) { return; } set_block_error(-2); return; } else { block->outptr[0][0] = stack[bottom]; } } }

inline T coth( T n ) { return 1 / tanh( n ); }

void test_trig( void ) { printf( "Testing trigonometric functions...\n" ); VERIFY( CompDbl( sin( PI ), 0.0 ) ); VERIFY( CompDbl( sin( 0.0 ), 0.0 ) ); VERIFY( CompDbl( sin( -PI ), 0.0 ) ); VERIFY( CompDbl( sin( PI / 2 ), 1.0 ) ); VERIFY( CompDbl( sin(- PI / 2 ), -1.0 ) ); VERIFY( CompDbl( cos( PI ), -1.0 ) ); VERIFY( CompDbl( cos( 0.0 ), 1.0 ) ); VERIFY( CompDbl( cos( -PI ), -1.0 ) ); VERIFY( CompDbl( cos( PI / 2 ), 0.0 ) ); VERIFY( CompDbl( cos(- PI / 2 ), 0.0 ) ); VERIFY( CompDbl( tan( PI ), 0.0 ) ); VERIFY( CompDbl( tan( 0.0 ), 0.0 ) ); VERIFY( CompDbl( tan( -PI ), 0.0 ) ); VERIFY( CompDbl( tan( PI / 4 ), 1.0 ) ); VERIFY( CompDbl( asin( 1.0 ), PI / 2 ) ); VERIFY( CompDbl( asin( 0.0 ), 0.0 ) ); VERIFY( CompDbl( asin( -1.0 ), -PI / 2 ) ); VERIFY( CompDbl( acos( 1.0 ), 0.0 ) ); VERIFY( CompDbl( acos( 0.0 ), PI / 2 ) ); VERIFY( CompDbl( acos( -1.0 ), PI ) ); VERIFY( CompDbl( atan( 1.0 ), PI / 4 ) ); VERIFY( CompDbl( atan( 0.0 ), 0.0 ) ); VERIFY( CompDbl( atan( -1.0 ), -PI / 4 ) ); VERIFY( CompDbl( atan( DBL_MAX ), PI / 2 ) ); VERIFY( CompDbl( atan( -DBL_MAX ), -PI / 2 ) ); VERIFY( CompDbl( atan2( 2.0, 2.0 ), PI / 4 ) ); VERIFY( CompDbl( atan2( 1.0, -1.0 ), 3 * PI / 4 ) ); VERIFY( CompDbl( atan2( -1.0, -1.0 ), -3 * PI / 4 ) ); VERIFY( CompDbl( atan2( -3.0, 3.0 ), -PI / 4 ) ); VERIFY( CompDbl( atan2( 0.0, 1.0 ), 0.0 ) ); VERIFY( CompDbl( atan2( 1.0, 0.0 ), PI / 2 ) ); VERIFY( CompDbl( atan2( -DBL_MAX, 1.0 ), -PI / 2 ) ); VERIFY( CompDbl( atan2( DBL_MAX, 1.0 ), PI / 2 ) ); VERIFY( CompDbl( atan2( 1.0, DBL_MAX ), 0.0 ) ); VERIFY( CompDbl( atan2( -1.0, DBL_MAX ), 0.0 ) ); VERIFY( CompDbl( hypot( 3.0, 4.0 ), 5.0 ) ); VERIFY( CompDbl( sinh( 1.0 ), 1.1752011936 ) ); VERIFY( CompDbl( sinh( 0.0 ), 0.0 ) ); VERIFY( CompDbl( cosh( 1.0 ), 1.5430806348 ) ); VERIFY( CompDbl( cosh( 0.0 ), 1.0 ) ); VERIFY( CompDbl( tanh( 1.0 ), 0.7615941560 ) ); VERIFY( CompDbl( tanh( 0.0 ), 0.0 ) ); #ifdef __WATCOMC__ /* Not in Microsoft libs. */ VERIFY( CompDbl( asinh( 1.1752011936 ), 1.0 ) ); VERIFY( CompDbl( asinh( 0.0 ), 0.0 ) ); VERIFY( CompDbl( acosh( 1.5430806348 ), 1.0 ) ); VERIFY( CompDbl( acosh( 1.0 ), 0.0 ) ); VERIFY( CompDbl( atanh( 0.7615941560 ), 1.0 ) ); VERIFY( CompDbl( atanh( 0.0 ), 0.0 ) ); #endif /* Note: sinh(1) = 1.175201193643802 sinh(0) = 0.000000000000000 cosh(1) = 1.543080634815244 cosh(0) = 1.000000000000000 tanh(1) = 0.761594155955765 tanh(0) = 0.000000000000000 */ }

void math (double d, int *ex, double *dp) { acos (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 8 } */ acosh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 10 } */ asin (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 12 } */ asinh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 14 } */ atan (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 16 } */ atanh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 18 } */ atan2 (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 20 } */ cbrt (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 22 } */ ceil (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 24 } */ copysign (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 26 } */ cos (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 28 } */ cosh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 30 } */ erf (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 32 } */ erfc (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 34 } */ exp (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 36 } */ exp2 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 38 } */ expm1 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 40 } */ fabs (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 42 } */ fdim (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 44 } */ floor (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 46 } */ fma (d, d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 48 } */ fmax (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 50 } */ fmin (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 52 } */ fmod (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 54 } */ frexp (d, ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 56 } */ hypot (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 58 } */ /* We don't generate the warning for ilogb. */ ilogb (d); ldexp (d, *ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 62 } */ lgamma (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 64 } */ llrint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 66 } */ llround (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 68 } */ log (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 70 } */ log10 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 72 } */ log1p (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 74 } */ log2 (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 76 } */ logb (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 78 } */ lrint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 80 } */ lround (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 82 } */ modf (d, dp); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 84 } */ nan (""); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 86 } */ nearbyint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 88 } */ nextafter (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 90 } */ nexttoward (d, 20.0L); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 92 } */ pow (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 94 } */ remainder (d, d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 96 } */ remquo (d, d, ex); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 98 } */ rint (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 100 } */ round (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 102 } */ scalbln (d, 100L); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 104 } */ scalbn (d, 100); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 106 } */ sin (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 108 } */ sinh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 110 } */ sincos (d, dp, dp); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 112 } */ sqrt (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 114 } */ tan (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 116 } */ tanh (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 118 } */ tgamma (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 120 } */ trunc (d); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..math.h.." "" { target *-*-* } 122 } */ }

int HFETApzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) { HFETAmodel *model = (HFETAmodel*)inModel; HFETAinstance *here; double gm; double gds; double xds; double ggs; double xgs; double ggd; double xgd; double ggspp; double ggdpp; double f; double m; for( ; model != NULL; model = model->HFETAnextModel ) { for( here = model->HFETAinstances; here != NULL; here = here->HFETAnextInstance) { if (here->HFETAowner != ARCHme) continue; gm = *(ckt->CKTstate0 + here->HFETAgm); gds = *(ckt->CKTstate0 + here->HFETAgds); xds = CDS*ckt->CKTomega; ggs = *(ckt->CKTstate0 + here->HFETAggs); xgs = *(ckt->CKTstate0 + here->HFETAqgs); ggd = *(ckt->CKTstate0 + here->HFETAggd); xgd = *(ckt->CKTstate0 + here->HFETAqgd); ggspp = *(ckt->CKTstate0 + here->HFETAggspp); ggdpp = *(ckt->CKTstate0 + here->HFETAggdpp); if(model->HFETAkappaGiven && here->HFETAdelf != 0.0) { f = ckt->CKTomega/2/M_PI; gds = gds*(1+0.5*model->HFETAkappa*(1+tanh((f-here->HFETAfgds)/here->HFETAdelf))); } m = here->HFETAm; *(here->HFETAdrainDrainPtr) += m * (model->HFETAdrainConduct); *(here->HFETAsourceSourcePtr) += m * (model->HFETAsourceConduct); *(here->HFETAgatePrimeGatePrimePtr) += m * (ggd+ggs+ggspp+ggdpp+model->HFETAgateConduct); *(here->HFETAdrainPrimeDrainPrimePtr) += m * (gds+ggd+model->HFETAdrainConduct+model->HFETAgf); *(here->HFETAsourcePrimeSourcePrimePtr) += m * (gds+gm+ggs+model->HFETAsourceConduct+model->HFETAgi); *(here->HFETAsourcePrmPrmSourcePrmPrmPtr) += m * (model->HFETAgi+ggspp); *(here->HFETAdrainPrmPrmDrainPrmPrmPtr) += m * (model->HFETAgf+ggdpp); *(here->HFETAdrainDrainPrimePtr) -= m * (model->HFETAdrainConduct); *(here->HFETAdrainPrimeDrainPtr) -= m * (model->HFETAdrainConduct); *(here->HFETAsourceSourcePrimePtr) -= m * (model->HFETAsourceConduct); *(here->HFETAsourcePrimeSourcePtr) -= m * (model->HFETAsourceConduct); *(here->HFETAgatePrimeDrainPrimePtr) -= m * (ggd); *(here->HFETAdrainPrimeGatePrimePtr) += m * (gm-ggd); *(here->HFETAgatePrimeSourcePrimePtr) -= m * (ggs); *(here->HFETAsourcePrimeGatePrimePtr) += m * (-ggs-gm); *(here->HFETAdrainPrimeSourcePrimePtr) += m * (-gds-gm); *(here->HFETAsourcePrimeDrainPrimePtr) -= m * (gds); *(here->HFETAsourcePrimeSourcePrmPrmPtr) -= m * (model->HFETAgi); *(here->HFETAsourcePrmPrmSourcePrimePtr) -= m * (model->HFETAgi); *(here->HFETAgatePrimeSourcePrmPrmPtr) -= m * (ggspp); *(here->HFETAsourcePrmPrmGatePrimePtr) -= m * (ggspp); *(here->HFETAdrainPrimeDrainPrmPrmPtr) -= m * (model->HFETAgf); *(here->HFETAdrainPrmPrmDrainPrimePtr) -= m * (model->HFETAgf); *(here->HFETAgatePrimeDrainPrmPrmPtr) -= m * (ggdpp); *(here->HFETAdrainPrmPrmGatePrimePtr) -= m * (ggdpp); *(here->HFETAgateGatePtr) += m * (model->HFETAgateConduct); *(here->HFETAgateGatePrimePtr) -= m * (model->HFETAgateConduct); *(here->HFETAgatePrimeGatePtr) -= m * (model->HFETAgateConduct); *(here->HFETAgatePrimeGatePrimePtr) += m * ((xgd+xgs) * s->real); *(here->HFETAgatePrimeGatePrimePtr+1) += m * ((xgd+xgs) * s->imag); *(here->HFETAdrainPrmPrmDrainPrmPrmPtr) += m * (xgd * s->real); *(here->HFETAdrainPrmPrmDrainPrmPrmPtr+1) += m * (xgd * s->imag); *(here->HFETAsourcePrmPrmSourcePrmPrmPtr) += m * (xgs * s->real); *(here->HFETAsourcePrmPrmSourcePrmPrmPtr+1) += m * (xgs * s->imag); *(here->HFETAgatePrimeDrainPrmPrmPtr) -= m * (xgd * s->real); *(here->HFETAgatePrimeDrainPrmPrmPtr+1) -= m * (xgd * s->imag); *(here->HFETAgatePrimeSourcePrmPrmPtr) -= m * (xgs * s->real); *(here->HFETAgatePrimeSourcePrmPrmPtr+1) -= m * (xgs * s->imag); *(here->HFETAdrainPrmPrmGatePrimePtr) -= m * (xgd * s->real); *(here->HFETAdrainPrmPrmGatePrimePtr+1) -= m * (xgd * s->imag); *(here->HFETAsourcePrmPrmGatePrimePtr) -= m * (xgs * s->real); *(here->HFETAsourcePrmPrmGatePrimePtr+1) -= m * (xgs * s->imag); *(here->HFETAdrainPrimeDrainPrimePtr) += m * (xds * s->real); *(here->HFETAdrainPrimeDrainPrimePtr+1) += m * (xds * s->imag); *(here->HFETAsourcePrimeSourcePrimePtr) += m * (xds * s->real); *(here->HFETAsourcePrimeSourcePrimePtr+1) += m * (xds * s->imag); *(here->HFETAdrainPrimeSourcePrimePtr) -= m * (xds * s->real); *(here->HFETAdrainPrimeSourcePrimePtr+1) -= m * (xds * s->imag); *(here->HFETAsourcePrimeDrainPrimePtr) -= m * (xds * s->real); *(here->HFETAsourcePrimeDrainPrimePtr+1) -= m * (xds * s->imag); } } return(OK); }

static double eval(Enode * const e, double const values[], double const params[], unordered_map<Enode *, unsigned> const & value_lookup, unordered_map<Enode *, unsigned> const & param_lookup) { if (e->isNumb()) { return e->getNumb(); } else if (e->isVar()) { auto it = value_lookup.find(e); if (it != value_lookup.end()) { return values[it->second]; } it = param_lookup.find(e); if (it != param_lookup.end()) { return params[it->second]; } DREAL_LOG_FATAL << "Can't find variable " << e; throw runtime_error("GSL eval: unmatched variable"); } else if (e->isTerm()) { switch (e->getCar()->getId()) { case ENODE_ID_PLUS: { Enode * p = e->getCdr(); double ret = eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); while (!p->isEnil()) { ret += eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); } return ret; } case ENODE_ID_MINUS: { Enode * p = e->getCdr(); double ret = eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); while (!p->isEnil()) { ret -= eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); } return ret; } case ENODE_ID_TIMES: { Enode * p = e->getCdr(); double ret = eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); while (!p->isEnil()) { ret *= eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); } return ret; } case ENODE_ID_DIV: { Enode * p = e->getCdr(); double ret = eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); while (!p->isEnil()) { ret /= eval(p->getCar(), values, params, value_lookup, param_lookup); p = p->getCdr(); } return ret; } case ENODE_ID_POW: { if (e->getArity() != 2) { throw runtime_error("GSL eval: pow not implemented"); } double const arg1 = eval(e->get1st(), values, params, value_lookup, param_lookup); double const arg2 = eval(e->get2nd(), values, params, value_lookup, param_lookup); return pow(arg1, arg2); } case ENODE_ID_ATAN2: { double const arg1 = eval(e->get1st(), values, params, value_lookup, param_lookup); double const arg2 = eval(e->get2nd(), values, params, value_lookup, param_lookup); return atan2(arg1, arg2); } case ENODE_ID_UMINUS: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return -arg; } case ENODE_ID_SIN: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return sin(arg); } case ENODE_ID_COS: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return cos(arg); } case ENODE_ID_TAN: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return tan(arg); } case ENODE_ID_SQRT: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return sqrt(arg); } case ENODE_ID_SAFESQRT: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); assert(arg >= 0); return sqrt(arg); } case ENODE_ID_EXP: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return exp(arg); } case ENODE_ID_LOG: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return log(arg); } case ENODE_ID_ASIN: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return asin(arg); } case ENODE_ID_ACOS: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return acos(arg); } case ENODE_ID_ATAN: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return atan(arg); } case ENODE_ID_SINH: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return sinh(arg); } case ENODE_ID_COSH: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return cosh(arg); } case ENODE_ID_TANH: { assert(e->getArity() == 1); double const arg = eval(e->get1st(), values, params, value_lookup, param_lookup); return tanh(arg); } default: return eval(e->getCar(), values, params, value_lookup, param_lookup); } } else if (e->isList()) { throw runtime_error("GSL eval: list"); } else if (e->isDef()) { throw runtime_error("GSL eval: def"); } else if (e->isEnil()) { throw runtime_error("GSL eval: enil"); } throw runtime_error("GSL eval: unknown"); }

void LibTanh(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->FP = tanh(Param[0]->Val->FP); }

float TanhFunction::value(float x) { return tanh(steepness*x); }

void domath (void) { #ifndef NO_DOUBLE double f1; double f2; int i1; f1 = acos (0.0); fprintf( stdout, "acos : %f\n", f1); f1 = acosh (0.0); fprintf( stdout, "acosh : %f\n", f1); f1 = asin (1.0); fprintf( stdout, "asin : %f\n", f1); f1 = asinh (1.0); fprintf( stdout, "asinh : %f\n", f1); f1 = atan (M_PI_4); fprintf( stdout, "atan : %f\n", f1); f1 = atan2 (2.3, 2.3); fprintf( stdout, "atan2 : %f\n", f1); f1 = atanh (1.0); fprintf( stdout, "atanh : %f\n", f1); f1 = cbrt (27.0); fprintf( stdout, "cbrt : %f\n", f1); f1 = ceil (3.5); fprintf( stdout, "ceil : %f\n", f1); f1 = copysign (3.5, -2.5); fprintf( stdout, "copysign : %f\n", f1); f1 = cos (M_PI_2); fprintf( stdout, "cos : %f\n", f1); f1 = cosh (M_PI_2); fprintf( stdout, "cosh : %f\n", f1); f1 = erf (42.0); fprintf( stdout, "erf : %f\n", f1); f1 = erfc (42.0); fprintf( stdout, "erfc : %f\n", f1); f1 = exp (0.42); fprintf( stdout, "exp : %f\n", f1); f1 = exp2 (0.42); fprintf( stdout, "exp2 : %f\n", f1); f1 = expm1 (0.00042); fprintf( stdout, "expm1 : %f\n", f1); f1 = fabs (-1.123); fprintf( stdout, "fabs : %f\n", f1); f1 = fdim (1.123, 2.123); fprintf( stdout, "fdim : %f\n", f1); f1 = floor (0.5); fprintf( stdout, "floor : %f\n", f1); f1 = floor (-0.5); fprintf( stdout, "floor : %f\n", f1); f1 = fma (2.1, 2.2, 3.01); fprintf( stdout, "fma : %f\n", f1); f1 = fmax (-0.42, 0.42); fprintf( stdout, "fmax : %f\n", f1); f1 = fmin (-0.42, 0.42); fprintf( stdout, "fmin : %f\n", f1); f1 = fmod (42.0, 3.0); fprintf( stdout, "fmod : %f\n", f1); /* no type-specific variant */ i1 = fpclassify(1.0); fprintf( stdout, "fpclassify : %d\n", i1); f1 = frexp (42.0, &i1); fprintf( stdout, "frexp : %f\n", f1); f1 = hypot (42.0, 42.0); fprintf( stdout, "hypot : %f\n", f1); i1 = ilogb (42.0); fprintf( stdout, "ilogb : %d\n", i1); /* no type-specific variant */ i1 = isfinite(3.0); fprintf( stdout, "isfinite : %d\n", i1); /* no type-specific variant */ i1 = isgreater(3.0, 3.1); fprintf( stdout, "isgreater : %d\n", i1); /* no type-specific variant */ i1 = isgreaterequal(3.0, 3.1); fprintf( stdout, "isgreaterequal : %d\n", i1); /* no type-specific variant */ i1 = isinf(3.0); fprintf( stdout, "isinf : %d\n", i1); /* no type-specific variant */ i1 = isless(3.0, 3.1); fprintf( stdout, "isless : %d\n", i1); /* no type-specific variant */ i1 = islessequal(3.0, 3.1); fprintf( stdout, "islessequal : %d\n", i1); /* no type-specific variant */ i1 = islessgreater(3.0, 3.1); fprintf( stdout, "islessgreater : %d\n", i1); /* no type-specific variant */ i1 = isnan(0.0); fprintf( stdout, "isnan : %d\n", i1); /* no type-specific variant */ i1 = isnormal(3.0); fprintf( stdout, "isnormal : %d\n", i1); /* no type-specific variant */ f1 = isunordered(1.0, 2.0); fprintf( stdout, "isunordered : %d\n", i1); f1 = j0 (1.2); fprintf( stdout, "j0 : %f\n", f1); f1 = j1 (1.2); fprintf( stdout, "j1 : %f\n", f1); f1 = jn (2,1.2); fprintf( stdout, "jn : %f\n", f1); f1 = ldexp (1.2,3); fprintf( stdout, "ldexp : %f\n", f1); f1 = lgamma (42.0); fprintf( stdout, "lgamma : %f\n", f1); f1 = llrint (-0.5); fprintf( stdout, "llrint : %f\n", f1); f1 = llrint (0.5); fprintf( stdout, "llrint : %f\n", f1); f1 = llround (-0.5); fprintf( stdout, "lround : %f\n", f1); f1 = llround (0.5); fprintf( stdout, "lround : %f\n", f1); f1 = log (42.0); fprintf( stdout, "log : %f\n", f1); f1 = log10 (42.0); fprintf( stdout, "log10 : %f\n", f1); f1 = log1p (42.0); fprintf( stdout, "log1p : %f\n", f1); f1 = log2 (42.0); fprintf( stdout, "log2 : %f\n", f1); f1 = logb (42.0); fprintf( stdout, "logb : %f\n", f1); f1 = lrint (-0.5); fprintf( stdout, "lrint : %f\n", f1); f1 = lrint (0.5); fprintf( stdout, "lrint : %f\n", f1); f1 = lround (-0.5); fprintf( stdout, "lround : %f\n", f1); f1 = lround (0.5); fprintf( stdout, "lround : %f\n", f1); f1 = modf (42.0,&f2); fprintf( stdout, "lmodf : %f\n", f1); f1 = nan (""); fprintf( stdout, "nan : %f\n", f1); f1 = nearbyint (1.5); fprintf( stdout, "nearbyint : %f\n", f1); f1 = nextafter (1.5,2.0); fprintf( stdout, "nextafter : %f\n", f1); f1 = pow (3.01, 2.0); fprintf( stdout, "pow : %f\n", f1); f1 = remainder (3.01,2.0); fprintf( stdout, "remainder : %f\n", f1); f1 = remquo (29.0,3.0,&i1); fprintf( stdout, "remquo : %f\n", f1); f1 = rint (0.5); fprintf( stdout, "rint : %f\n", f1); f1 = rint (-0.5); fprintf( stdout, "rint : %f\n", f1); f1 = round (0.5); fprintf( stdout, "round : %f\n", f1); f1 = round (-0.5); fprintf( stdout, "round : %f\n", f1); f1 = scalbln (1.2,3); fprintf( stdout, "scalbln : %f\n", f1); f1 = scalbn (1.2,3); fprintf( stdout, "scalbn : %f\n", f1); /* no type-specific variant */ i1 = signbit(1.0); fprintf( stdout, "signbit : %i\n", i1); f1 = sin (M_PI_4); fprintf( stdout, "sin : %f\n", f1); f1 = sinh (M_PI_4); fprintf( stdout, "sinh : %f\n", f1); f1 = sqrt (9.0); fprintf( stdout, "sqrt : %f\n", f1); f1 = tan (M_PI_4); fprintf( stdout, "tan : %f\n", f1); f1 = tanh (M_PI_4); fprintf( stdout, "tanh : %f\n", f1); f1 = tgamma (2.1); fprintf( stdout, "tgamma : %f\n", f1); f1 = trunc (3.5); fprintf( stdout, "trunc : %f\n", f1); f1 = y0 (1.2); fprintf( stdout, "y0 : %f\n", f1); f1 = y1 (1.2); fprintf( stdout, "y1 : %f\n", f1); f1 = yn (3,1.2); fprintf( stdout, "yn : %f\n", f1); #endif }

__device__ inline double occaCuda_fastTanh(const double x){ return tanh(x); }

void Sound::Sound::Calc () { _balance = int (127 * tanh (float(X) / 200) + 128); _volume = 50000 * Volume / (X*X + Y*Y + 50000); }

Constante* Reel::tanh_(){ _reel=tanh(_reel); return this; }

Real T_FTIME() { // return 1.0; return 1+tanh(rT*TIME); }

__device__ void double_precision_math_functions() { int iX; double fX, fY; acos(1.0); acosh(1.0); asin(0.0); asinh(0.0); atan(0.0); atan2(0.0, 1.0); atanh(0.0); cbrt(0.0); ceil(0.0); copysign(1.0, -2.0); cos(0.0); cosh(0.0); cospi(0.0); cyl_bessel_i0(0.0); cyl_bessel_i1(0.0); erf(0.0); erfc(0.0); erfcinv(2.0); erfcx(0.0); erfinv(1.0); exp(0.0); exp10(0.0); exp2(0.0); expm1(0.0); fabs(1.0); fdim(1.0, 0.0); floor(0.0); fma(1.0, 2.0, 3.0); fmax(0.0, 0.0); fmin(0.0, 0.0); fmod(0.0, 1.0); frexp(0.0, &iX); hypot(1.0, 0.0); ilogb(1.0); isfinite(0.0); isinf(0.0); isnan(0.0); j0(0.0); j1(0.0); jn(-1.0, 1.0); ldexp(0.0, 0); lgamma(1.0); llrint(0.0); llround(0.0); log(1.0); log10(1.0); log1p(-1.0); log2(1.0); logb(1.0); lrint(0.0); lround(0.0); modf(0.0, &fX); nan("1"); nearbyint(0.0); nextafter(0.0, 0.0); fX = 1.0; norm(1, &fX); norm3d(1.0, 0.0, 0.0); norm4d(1.0, 0.0, 0.0, 0.0); normcdf(0.0); normcdfinv(1.0); pow(1.0, 0.0); rcbrt(1.0); remainder(2.0, 1.0); remquo(1.0, 2.0, &iX); rhypot(0.0, 1.0); rint(1.0); fX = 1.0; rnorm(1, &fX); rnorm3d(0.0, 0.0, 1.0); rnorm4d(0.0, 0.0, 0.0, 1.0); round(0.0); rsqrt(1.0); scalbln(0.0, 1); scalbn(0.0, 1); signbit(1.0); sin(0.0); sincos(0.0, &fX, &fY); sincospi(0.0, &fX, &fY); sinh(0.0); sinpi(0.0); sqrt(0.0); tan(0.0); tanh(0.0); tgamma(2.0); trunc(0.0); y0(1.0); y1(1.0); yn(1, 1.0); }

void c_dd_tanh(const double *a, double *b) { dd_real bb; bb = tanh(dd_real(a)); TO_DOUBLE_PTR(bb, b); }

void grAddSmoke(tCarElt *car, double t) { int i = 0; tgrSmoke * tmp; sgVec3 vtx; ssgVertexArray *shd_vtx ; tgrCarInstrument *curInst; tdble val; int index; if (!grSmokeMaxNumber) { return; } for (i = 0; i < 4; i++) { if (car->pub.speed > 0.03f) { // 0.03 -> sqrt(0.001) if (smokeManager->number < grSmokeMaxNumber) { if ((t - timeSmoke[car->index*4+i]) < grSmokeDeltaT) { continue; } else { timeSmoke[car->index*4+i] = t; } sgVec3 cur_clr; tdble init_speed; tdble threshold = 0.1f; tdble smoke_life_coefficient = 30.0f; tdble smoke_speed_coefficient = 0.0f; cur_clr[0] = 0.8f; cur_clr[1] = 0.8f; cur_clr[2] = 0.8f; init_speed = 0.01f; if (car->priv.wheel[i].seg) { // sanity check const char* surface = car->priv.wheel[i].seg->surface->material; if (strstr(surface, "sand")) { cur_clr[0] = 0.8f; cur_clr[1] = 0.7f + urandom()*0.1f; cur_clr[2] = 0.4f + urandom()*0.2f; init_speed = 0.5f; threshold = 0.05f; smoke_life_coefficient = 12.5f; smoke_speed_coefficient = 0.25f; } else if (strstr(surface, "dirt")) { cur_clr[0] = 0.7f + urandom()*0.1f; cur_clr[1] = 0.6f + urandom()*0.1f; cur_clr[2] = 0.5f + urandom()*0.1f; init_speed = 0.45f; threshold=0.0f; smoke_life_coefficient = 10.0f; smoke_speed_coefficient = 0.5f; } else if (strstr(surface,"mud")) { cur_clr[0] = 0.65f; cur_clr[1] = 0.4f + urandom()*0.2f; cur_clr[2] = 0.3f + urandom()*0.2f; init_speed = 0.4f; threshold = 0.2f; smoke_speed_coefficient = 0.05f; } else if (strstr(surface,"gravel")) { cur_clr[0] = 0.6f; cur_clr[1] = 0.6f; cur_clr[2] = 0.6f; init_speed = 0.35f; smoke_life_coefficient = 20.0f; smoke_speed_coefficient = 0.1f; } else if (strstr(surface,"grass")) { cur_clr[0] = 0.4f + urandom()*0.2f; cur_clr[1] = 0.5f + urandom()*0.1f; cur_clr[2] = 0.3f + urandom()*0.1f; init_speed = 0.3f; smoke_life_coefficient = 25.0f; } else { cur_clr[0] = 0.8f; cur_clr[1] = 0.8f; cur_clr[2] = 0.8f; init_speed = 0.01f; } } smoke_life_coefficient = smoke_life_coefficient * (1.0f - urandom()*urandom()); tdble spd_fx=tanh(0.001f*car->_reaction[i])*smoke_speed_coefficient*car->pub.speed; if (car->_skid[i] + 0.025f*urandom()*spd_fx>urandom() + threshold) {// instead of 0.3, to randomize float init_speed_z = 0.1f; float stretch_factor = 0.5f; tdble sinCarYaw = sin(car->_yaw); tdble cosCarYaw = cos(car->_yaw); shd_vtx = new ssgVertexArray(1); //shd_clr = new ssgColourArray(1); tmp = (tgrSmoke *) malloc(sizeof(tgrSmoke)); vtx[0] = car->priv.wheel[i].relPos.x; vtx[1] = car->priv.wheel[i].relPos.y; vtx[2] = car->priv.wheel[i].relPos.z-car->_wheelRadius(i)*1.0f+ 0.5f * SMOKE_INIT_SIZE; tdble stretchX = 0.1f * (spd_fx + stretch_factor * fabs(car->_speed_X)); tdble stretchY = 0.1f * (spd_fx + stretch_factor * fabs(car->_speed_Y)); vtx[0] -= 0.05f*car->_speed_x; shd_vtx->add(vtx); tmp->smoke = new ssgVtxTableSmoke(shd_vtx,SMOKE_INIT_SIZE,SMOKE_TYPE_TIRE); init_speed = urandom()*init_speed; tmp->smoke->vvx = -sinCarYaw * car->_wheelSlipSide(i); tmp->smoke->vvy = cosCarYaw * car->_wheelSlipSide(i); tmp->smoke->vvx += cosCarYaw * car->_wheelSlipAccel(i); tmp->smoke->vvy += sinCarYaw * car->_wheelSlipAccel(i); tmp->smoke->vvz = init_speed_z; tmp->smoke->vvx *= init_speed; tmp->smoke->vvy *= init_speed; tmp->smoke->setState(mst); tmp->smoke->setCullFace(0); //printf("%f\n", car->_reaction[i]); tmp->smoke->max_life = grSmokeLife * (car->_skid[i]*car->pub.speed+urandom()*spd_fx)/ smoke_life_coefficient; for (int c = 0; c < 3; c++) { tmp->smoke->cur_col[c] = cur_clr[c]; } tmp->smoke->cur_life = 0; tmp->smoke->sizex = VX_INIT + stretchX; tmp->smoke->sizey = VY_INIT + stretchY; tmp->smoke->sizez = VZ_INIT + 0.1f * spd_fx; tmp->smoke->init_alpha = 1.0/(1.0+0.1*spd_fx); tmp->smoke->vexp = V_EXPANSION+(car->_skid[i]+.1*spd_fx)*(((float)rand()/(float)RAND_MAX)); tmp->smoke->smokeType = SMOKE_TYPE_TIRE; tmp->smoke->smokeTypeStep = 0; tmp->next = NULL; tmp->smoke->lastTime = t; tmp->smoke->transform(grCarInfo[car->index].carPos); SmokeAnchor->addKid(tmp->smoke); smokeManager->number++; if (smokeManager->smokeList==NULL) { smokeManager->smokeList = tmp; } else { tmp->next = smokeManager->smokeList; smokeManager->smokeList = tmp; } } } } } if (car->_exhaustNb && (car->pub.speed > 3.0f)) { if (smokeManager->number < grSmokeMaxNumber) { index = car->index; /* current car's index */ if ((t - timeFire[index]) > grFireDeltaT) { timeFire[index] = t; curInst = &(grCarInfo[index].instrument[0]); val = ((curInst->rawPrev - curInst->minValue) / curInst->maxValue) - ((*(curInst->monitored) - curInst->minValue) / curInst->maxValue); curInst->rawPrev = *(curInst->monitored); if (val > 0.1) { grCarInfo[index].fireCount = (int)(10.0 * val * car->_exhaustPower); } if (grCarInfo[index].fireCount) { grCarInfo[index].fireCount--; //if (car->priv.smoke>urandom()) { //car->priv.smoke = val * car->_exhaustPower; for (i = 0; i < car->_exhaustNb; i++) { shd_vtx = new ssgVertexArray(1); tmp = (tgrSmoke *) malloc(sizeof(tgrSmoke)); vtx[0] = car->_exhaustPos[i].x; vtx[1] = car->_exhaustPos[i].y; vtx[2] = car->_exhaustPos[i].z; shd_vtx->add(vtx); tmp->smoke = new ssgVtxTableSmoke(shd_vtx,SMOKE_INIT_SIZE*4,SMOKE_TYPE_ENGINE); tmp->smoke->setState(mstf0); tmp->smoke->setCullFace(0); tmp->smoke->max_life = grSmokeLife/8; tmp->smoke->step0_max_life = (grSmokeLife)/50.0; tmp->smoke->step1_max_life = (grSmokeLife)/50.0+ tmp->smoke->max_life/2.0; tmp->smoke->cur_life = 0; //tmp->smoke->init_alpha = 0.9; tmp->smoke->sizex = VX_INIT*4; tmp->smoke->sizey = VY_INIT*4; tmp->smoke->sizez = VZ_INIT*4; tmp->smoke->vexp = V_EXPANSION+5.0*rand()/(RAND_MAX+1.0) * car->_exhaustPower / 2.0; //tmp->smoke->vexp = V_EXPANSION+5.0*(((float)rand()/(float)RAND_MAX)) * car->_exhaustPower / 2.0; tmp->smoke->smokeType = SMOKE_TYPE_ENGINE; tmp->smoke->smokeTypeStep = 0; tmp->next = NULL; tmp->smoke->lastTime = t; tmp->smoke->transform(grCarInfo[index].carPos); SmokeAnchor->addKid(tmp->smoke); smokeManager->number++; if (smokeManager->smokeList==NULL) { smokeManager->smokeList = tmp; } else { tmp->next = smokeManager->smokeList; smokeManager->smokeList = tmp; } } } } } } }

static VALUE math_tanh(VALUE obj, VALUE x) { Need_Float(x); return DBL2NUM(tanh(RFLOAT_VALUE(x))); }

double kernel_sigmoid(int i, int j) const { return tanh(gamma*dot(x[i],x[j])+coef0); }

float tanhf(float x) { return (float) tanh(x); }

double tanhl( double x ) { return (double)tanh((double) x); }

void ExprCopy::visit(const ExprTanh& e) { if (unary_copy(e,tanh )) clone.insert(e,&tanh (EXPR)); }

double ReadMLP1::ActivationFnc(double x) const { // hyperbolic tan return tanh(x); }