Function parser for C++ v2.7 by Warp.
=====================================
Optimization code contributed by Bisqwit (http://iki.fi/bisqwit/)
The usage license of this library is located at the end of this text file.
What's new in v2.7
------------------
- Changed precedence rules for unary minus and the power operator (^) to
make it closer in functionality to the power "operator" in mathematics
(ie. superscript):
* Consecutive power operators at the same precedence level are
evaluated from right to left. That is, for example "2^3^4" is
now evaluated as if it had been written as "2^(3^4)" (and not
as "(2^3)^4" like in previous versions).
* The unary minus in the base of the power has now a lower precedence
than the power operator. That is, "-2^3" will be evaluated as if
written as "-(2^3)", ie. the result is "-8" (and not "8" like in
previous versions). The unary minus in the exponent is still
evaluated first because of the right-left precedence change above
(that is, "-2^-3" is evaluated as "-(2^(-3))").
- Fixed a bug in the copy-on-write engine.
=============================================================================
- Preface
=============================================================================
Often people need to ask some mathematical expression from the user and
then evaluate values for that expression. The simplest example is a program
which draws the graphic of a user-defined function on screen.
This library adds C-style function string parsing to the program. This
means that you can evaluate the string "sqrt(1-x^2+y^2)" with given values
of 'x' and 'y'.
The library is intended to be very fast. It byte-compiles the function
string at parse time and interpretes this byte-code at evaluation time.
The evaluation is straightforward and no recursions are done (uses stack
arithmetic).
Empirical tests show that it indeed is very fast (specially compared to
libraries which evaluate functions by just interpreting the raw function
string).
The library is made in ISO C++ and requires a standard-conforming C++
compiler.
=============================================================================
- Usage
=============================================================================
To use the FunctionParser class, you have to include "fparser.hh". When
compiling, you have to compile fparser.cc and link it to the main program.
You can also make a library from the fparser.cc (see the help on your
compiler to see how this is done).
* Conditional compiling:
---------------------
There is a set of precompiler options at the beginning of fparser.cc
which can be used for setting certain features on or off. These lines
can be commented or uncommented depending on the desired behaviour:
NO_ASINH : (Default on)
By default the library does not support the asinh(), acosh()
and atanh() functions because they are not part of the ISO C++
standard. If your compiler supports them and you want the
parser to support them as well, comment this line.
DISABLE_EVAL : (Default off)
The eval() function can be dangerous because it can cause an
infinite recursion in the parser when not used properly (which
causes the function stack created by the compiler to overflow).
If this possibility should be prevented then the eval() function
can be disabled completely by uncommenting this line.
SUPPORT_OPTIMIZER : (Default on)
If you are not going to use the Optimize() method, you can comment
this line out to speed-up the compilation of fparser.cc a bit, as
well as making the binary a bit smaller. (Optimize() can still be
called, but it will not do anything.)
* Copying and assignment:
----------------------
The class implements a safe copy constructor and assignment operator.
It uses the copy-on-write technique for efficiency. This means that
when copying or assigning a FunctionParser instance, the internal data
(which in some cases can be quite lengthy) is not immediately copied
but only when the contents of the copy (or the original) are changed.
This means that copying/assigning is a very fast operation, and if
the copies are never modified then actual data copying never happens
either.
The Eval() and EvalError() methods of the copy can be called without
the internal data being copied.
Calling Parse(), Optimize() or the user-defined constant/function adding
methods will cause a deep-copy.
(C++ basics: The copy constructor is called when a new FunctionParser
instance is initialized with another, ie. like:
FunctionParser fp2 = fp1; // or: FunctionParser fp2(fp1);
or when a function takes a FunctionParser instance as parameter, eg:
void foo(FunctionParser p) // takes an instance of FunctionParser
{ ... }
The assignment operator is called when a FunctionParser instance is
assigned to another, like "fp2 = fp1;".)
* Short descriptions of FunctionParser methods:
--------------------------------------------
int Parse(const std::string& Function, const std::string& Vars,
bool useDegrees = false);
Parses the given function and compiles it to internal format.
Return value is -1 if successful, else the index value to the location
of the error.
const char* ErrorMsg(void) const;
Returns an error message corresponding to the error in Parse(), or 0 if
no such error occurred.
ParseErrorType GetParseErrorType() const;
Returns the type of parsing error which occurred. Possible return types
are described in the long description.
double Eval(const double* Vars);
Evaluates the function given to Parse().
int EvalError(void) const;
Returns 0 if no error happened in the previous call to Eval(), else an
error code >0.
void Optimize();
Tries to optimize the bytecode for faster evaluation.
bool AddConstant(const std::string& name, double value);
Add a constant to the parser. Returns false if the name of the constant
is invalid, else true.
bool AddFunction(const std::string& name,
double (*functionPtr)(const double*),
unsigned paramsAmount);
Add a user-defined function to the parser (as a function pointer).
Returns false if the name of the function is invalid, else true.
bool AddFunction(const std::string& name, FunctionParser&);
Add a user-defined function to the parser (as a FunctionParser instance).
Returns false if the name of the function is invalid, else true.
* Long descriptions of FunctionParser methods:
-------------------------------------------
---------------------------------------------------------------------------
int Parse(const std::string& Function, const std::string& Vars,
bool useDegrees = false);
---------------------------------------------------------------------------
Parses the given function (and compiles it to internal format).
Destroys previous function. Following calls to Eval() will evaluate
the given function.
The strings given as parameters are not needed anymore after parsing.
Parameters:
Function : String containing the function to parse.
Vars : String containing the variable names, separated by commas.
Eg. "x,y", "VarX,VarY,VarZ,n" or "x1,x2,x3,x4,__VAR__".
useDegrees: (Optional.) Whether to use degrees or radians in
trigonometric functions. (Default: radians)
Variables can have any size and they are case sensitive (ie. "var",
"VAR" and "Var" are *different* variable names). Letters, digits an
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于安卓android闹钟源码 多个AlarmClock闹钟程序源码合集,仅供学习及设计参考。 AlarmClock.tar.gz AlarmTest.zip AndroidRTC-master.zip Android自动开关机实现.rar DeskClockApp-4-10 dreamDroid-2160fcf657531.zip DRLAlarmClock_01.rar FILAlarmApp-7a9755e71767b47f86df97c2d3e3b945c2d1d852.zip Note rtcmix-android-master.zip RTCommonDemo-master.zip sleep-guardian-master.zip SmartAlarm-b31b63b078c6f02f0fc4c1f977886c6baa8b7e2a.zip SystemClo
资源推荐
资源详情
资源评论
收起资源包目录
基于安卓android闹钟源码 多个AlarmClock闹钟程序源码合集.zip (2004个子文件)
xmlparse.c 196KB
headers.c 194KB
analyse.c 166KB
encoder.c 150KB
ratecontrol.c 117KB
macroblock.c 80KB
pixel.c 79KB
slicetype.c 77KB
cabac.c 76KB
sndlibsupport.c 55KB
macroblock.c 53KB
lex.conf.c 53KB
pmwinmm.c 51KB
me.c 50KB
lex.yy.c 49KB
rdo.c 47KB
common.c 47KB
io.c 47KB
pixel.c 47KB
cabac.c 46KB
xmltok_impl.c 45KB
trees.c 44KB
mc.c 42KB
xmltok.c 42KB
y.tab.c 41KB
deblock.c 38KB
rtcmix_wrap.c 34KB
xmlrole.c 33KB
dct.c 32KB
mc-c.c 31KB
set.c 30KB
predict.c 30KB
frame.c 30KB
sound.c 29KB
vlc.c 28KB
portmidi.c 28KB
native-audio-jni.c 27KB
cavlc.c 26KB
pmlinuxalsa.c 25KB
denoise.c 24KB
quant.c 24KB
pmmacosxcm.c 22KB
mvpred.c 22KB
mc.c 22KB
dct.c 21KB
predict-c.c 20KB
deblock.c 17KB
stgran.c 15KB
test.c 15KB
visualize.c 14KB
setell.c 14KB
quant.c 14KB
midithru.c 14KB
convolve.c 14KB
set.c 13KB
cpu.c 13KB
builtin.c 12KB
minc_functions.c 12KB
midithread.c 12KB
modgens.c 11KB
win32thread.c 10KB
mc-c.c 10KB
latency.c 10KB
lookahead.c 10KB
makegen.c 10KB
sysex.c 10KB
gen1.c 8KB
sgran.c 8KB
display-x11.c 8KB
predict.c 7KB
roomset.c 6KB
setup.c 6KB
sym.c 6KB
tuning.c 6KB
threadpool.c 5KB
wow.c 5KB
monitor.c 5KB
ug_intro.c 5KB
gen20.c 5KB
predict-c.c 5KB
gen2.c 4KB
fplot.c 4KB
message.c 4KB
hplset.c 4KB
getsample.c 4KB
cfr4syn.c 4KB
sset.c 4KB
cfr4tr.c 4KB
fft.c 4KB
osdep.c 4KB
fft.c 4KB
ptmacosx_cf.c 4KB
pitchconv.c 4KB
ptlinux.c 4KB
fft.c 4KB
ptmacosx_mach.c 4KB
path.c 4KB
lpcheader.c 3KB
path.c 3KB
bitstream.c 3KB
共 2004 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
GJZGRB
- 粉丝: 1543
- 资源: 6256
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功