primitiv.cxx
来自「标准的GP源代码,由Andy Singleton维护」· CXX 代码 · 共 121 行
CXX
121 行
// primitiv.cxx // W. Langdon cs.ucl.ac.uk// version "$Revision: 1.12 $"// Copyright Andy Singleton, 1993,1994// This code is released for non-commercial use only// For questions or upgrades contact:// Andy Singleton, Creation Mechanics Inc.// PO Box 248, Peterborough, NH 03458// Internet: p00396@psilink.com// Compuserve 73313,757// Phone: (603) 563-7757 //Modifications (in reverse order)//WBL 30 Nov 1995 Add order reversed SUB and DIV//WBL 26 Oct 1995 Restore Mul, Div and Abs//WBL 15 Oct 1995 Add TIMINGS//WBL 23 Jan 1995 Restore IFlteEval//WBL 2 May 1994 Real number support removed//**************************************************************************// Standard Functions// includes ConstFunc (numeric constants)// ADD,SUB,MUL,DIV,SINE,ABS,ADD4,PROG4,BOOL,NOT,AND,OR,IF,IFlte//**************************************************************************#include "pch.h"#include "chrome.h"#include "prob.h"#ifdef TIMINGS#include "time.h"#endif#include "primitiv.h"extern char scratch[100];#ifdef FASTEVAL extern evalnode* IpGlobal; extern Chrome* ChromeGlobal;#endifOPDEF(ConstEval) {return 127-GETIDX;}// print the value, not the namechar * ConstFunc::getprint(Chrome* st) {sprintf(scratch,"%d",127-VARNUM(st->expr[st->ip]));return scratch;}#ifndef ANT_LIB // Add two arguments. Note that argnum = 2OPDEF(AddEval) {return EVAL + EVAL;} // Subtract two argumentsOPDEF(SubEval) {return EVAL - EVAL;}OPDEF(SubREval) {return -EVAL + EVAL;} //reversed order of arguments//OPDEF(MulEval) {retval rval= EVAL * EVAL; return BOUNDF(rval);}OPDEF(MulEval) {return EVAL * EVAL;} //retval!=float // "Protected" divisionOPDEF(DivEval){ retval numerator,denominator;//,rval; numerator = EVAL; denominator = EVAL; if (denominator !=0)// rval = numerator/denominator; return numerator/denominator; //retval!=float else// rval=1; return 1; //retval!=float// return BOUNDF(rval);}OPDEF(DivREval) //reversed order of arguments{ retval numerator,denominator;//,rval; denominator = EVAL; numerator = EVAL; if (denominator !=0)// rval = numerator/denominator; return numerator/denominator; //retval!=float else// rval=1; return 1; //retval!=float// return BOUNDF(rval);}OPDEF(AbsEval) // Absolute value{ retval arg = EVAL; return (arg > 0 ? arg : -arg);}OPDEF(IflteEval) //IfLTE(condition1islessthan,condition2,dothis,dothat){ retval rval; rval=EVAL; if (rval<=EVAL) {#ifdef TIMINGS ThisTimmer->opt_time(IP);#endif rval=EVAL; IP++; // Jump the third expression TRAVERSE(); IP--; // And back up one (since EVAL increments) } else { IP++; TRAVERSE(); // Jump the second expression IP--; // Back up for EVAL#ifdef TIMINGS ThisTimmer->opt_time(IP);#endif rval=EVAL; } return rval;}#endif //ANT_LIB
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?