⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piecewisefnsamples.cpp

📁 精确的函数表达模板,里面包含了许多C和C++的函数表达模板
💻 CPP
字号:
/****************************************************************************
 * Copyright (C) 2001        Piece Wise Functions
 *                           Carlo Galotto
 *                           Italy
 *                           Email: carlo.galotto@libero.it
 *                                  cgalotto@hotmail.com
 *
 *
 * This framework is free  software; you can  redistribute it and/or modify
 * it. This framework is distributed  in the  hope  that  it  will  be useful,
 * but WITHOUT ANY WARRANTY;  without even the   implied  warranty of
 * MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.
 * The proposed framework is based upon the paper "Expression Templates" by
 * Todd Veldhuizen.
 ****************************************************************************/

//---------------------------------------------------------------------------

#pragma hdrstop
#include "PieceWiseFn.h"
//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
   Variable<double> x;
   double y;

   PieceWiseFn<double> fn1( 1/(x-1), x > 1 );            // 1
   y = fn1(0);
   y = fn1(1);
   y = fn1(2);

   PieceWiseFn<double> fn2( -x*x + 3.14*x + 1 );         // 2

   Literal<double> m = 2;
   Literal<double> c = 1;
   PieceWiseFn<double> fn3;                              // 3

   bool res;
   PieceWiseFn<double, bool> dom1(x >= c/m && x < 2*c/m);
   res = dom1(0);
   res = dom1(0.5);
   res = dom1(0.6);
   res = dom1(1);

   fn3.Add(m*x-c,  x >= c/m && x < 2*c/m );                  // 3.1
   fn3.Add(-m*(x-2*c/m)+c, (x >= 2*c/m) && (x <= 3*c/m) );   // 3.2

   y = fn3(0);                                         // 4
   y = fn3(0.5);                                       // 4
   y = fn3(1);                                         // 4
   y = fn3(1.4);                                       // 4
   y = fn3(1.5);                                       // 4
   y = fn3(2.3);                                       // 4

   return 0;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -