📄 ranges.h
字号:
#include <iostream.h>#include <math.h>#include "Array.h"#define abs(x) (((x) < 0) ? -(x) : (x))#define max(x1,x2) (((x1) > (x2)) ? (x1) : (x2))typedef float Real;///////////////////////////////////////////////////////////////////////////// Ranges.h /////////////////////////////////////////////////////////////////////////////class Ranges { public: Ranges(); ~Ranges();//// Main member functions// void initR(int); void showR();//// Support member functions// Real lowRange(int); Real highRange(int); Real expRange(int); private: SimpleFArray paramLows; // Lower bounds on the parameters. SimpleFArray paramHighs; // Upper bounds on the parameters. SimpleFArray exps; // Starting (highest) exponents.};///////////////////////////////////////////////////////////////////////////// Ranges.cc /////////////////////////////////////////////////////////////////////////////Ranges::Ranges() {}Ranges::~Ranges() {//// Standard destructor// paramLows.~SimpleFArray(); paramHighs.~SimpleFArray(); exps.~SimpleFArray();}void Ranges::initR(int np) {//// This routine initializes the parameter ranges, and chooses the value // of the starting bit, which is the largest power of two needed. The // value of the starting bit is chosen so that the first bit is the highest // power of two that is lower than the magnitude of the larger parameter // boundary. In other words, there are no wasted bits. If the parameter // range is from 0.0 to 0.1, then it makes no sense to have bits that // represent 1/8, 1/4, 1/2, 1, 2, 4, etc. It should start at 1/16, and go // down from there to 1/32, 1/64, etc. It calculates the starting bit to // be the one that yields the greatest accuracy. This allows the parameter // ranges to vary over virtuall any range (within machine accuracy).// paramLows.setSize(np); paramHighs.setSize(np); exps.setSize(np); int i; Real mpi; for (i = 0;i < np;i++) { cin >> paramLows[i] >> paramHighs[i]; mpi = max(abs(paramLows[i]),abs(paramHighs[i])); Real expsf = log(mpi)/log(2.0); if (expsf != Real(int(log(mpi)/log(2.0)))) exps[i] = Real(int(expsf+100.0)-100); else exps[i] = Real(int(expsf+100.0) - 101); exps[i] = pow(2.0,exps[i]); }}void Ranges::showR() {//// This routine prints out the parameter ranges for display purposes.// int np = paramLows.numElts(); cout << "===================================" << endl; cout << "Information about the " << np << " parameters." << endl; for (int i = 0;i < np;i++) { cout << "---------------------------" << endl; cout << "Information for parameter " << i << endl; cout << "Lower bound is " << paramLows[i] << endl; cout << "Upper bound is " << paramHighs[i] << endl; cout << "Exponent is " << exps[i] << endl; } cout << "---------------------------" << endl; cout << "===================================" << endl;}//// The following three functions simply return the specified value of the array.//Real Ranges::lowRange(int i) { return paramLows[i];}Real Ranges::highRange(int i) { return paramHighs[i];}Real Ranges::expRange(int i) { return exps[i];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -