utilq.cpp
来自「算断裂的」· C++ 代码 · 共 93 行
CPP
93 行
// ------------------------------------------------------------------// util.cpp//// This file defines some global functions used by QMG routines.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University. All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software. // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#include<cctype>#include "qnamesp.h"namespace QMG { // ------------------------------------------------------------------ // QMG::random_real() // Marsaglia random number number generator. If init is 1, restart, else if init // is 0 (default), return a random real number in [0,1]. // See http://www.mathworks.com/publications/newsletter/pdf/Cleve.pdf Real random_real(int init) { static int i; static Real z[32]; static Real b; if (init) { i = 0; for (int j = 0; j < 32; ++j) z[j] = sin((double)(1039 * j)) * sin((double)(1039 * j)); b = 0.0; return 0.0; } else { z[i] = z[(i+20)&31] - z[(i+5)&31] - b; if (z[i] < 0) { z[i] += 1.0; b = MACHINE_EPS; } else { b = 0.0; } Real rval = z[i]; i = (i + 1) & 31; return rval; } } // Eat the white characters in an istream istream& eatwhite(istream& is) { char c; for (;;) { if (!is.get(c)) break; if (!isspace(c)) { is.putback(c); break; } } return is; } // ------------------------------------------------------------------ // QMG::compare_nocase // Compare two strings ignoring case. int compare_nocase(const string& s1, const string& s2) { string::const_iterator p2 = s2.begin(); for (string::const_iterator p1 = s1.begin(); p1 != s1.end(); ++p1) { if (p2 == s2.end()) return 1; if (toupper(*p1) != toupper(*p2)) return (toupper(*p1) < toupper(*p2)) ? -1 : 1; ++p2; } return (p2 == s2.end())? 0 : -1; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?