[GiNaC-devel] Improvements for the code for the Lanczos method.
Sheplyakov Alexei
varg at theor.jinr.ru
Thu Jan 18 08:56:51 CET 2007
Hi, Chris!
> if (coeffs_12.size() != 12) {
> std::cerr << "Fatal: array of size 12 does not have size 12" << std::endl;
> exit(1);
> }
First of all, libraries should not be spamming std{out,err}. Secondly,
exit(1) makes debugging unnecessary complicated (I really, _really_ hate
libraries which exit() on error!). Last, you should have #include'ed
the header <cstdlib> where exit is declared.
I suggest to remove all that cruft and use exceptions instead.
Best regards,
Alexei
---
ginac/numeric.cpp | 28 +++++++++++-----------------
1 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp
index eed6624..55b3b53 100644
--- a/ginac/numeric.cpp
+++ b/ginac/numeric.cpp
@@ -1670,10 +1670,9 @@ lanczos_coeffs::lanczos_coeffs()
coeffs_12.push_back("13.80379833961490898061357227729422691903");
coeffs_12.push_back("-0.0807817619724537563116612761921260762075");
coeffs_12.push_back("3.47974801622326717770813986587340515986E-5");
- if (coeffs_12.size() != 12) {
- std::cerr << "Fatal: array of size 12 does not have size 12" << std::endl;
- exit(1);
- }
+ if (coeffs_12.size() != 12)
+ throw std::logic_error("Fatal: array of size 12 does not have size 12");
+
std::vector<cln::cl_N> &coeffs_30 = coeffs[1];
coeffs_30.reserve(30);
/* thirty coefficients follow. */
@@ -1707,10 +1706,9 @@ lanczos_coeffs::lanczos_coeffs()
coeffs_30.push_back("8.5728436055212340846907439451102962820713733082683634385104363203776378266115E-12");
coeffs_30.push_back("-3.9175430218003196379961975369936752665267219444417121562332986822123821080906E-17");
coeffs_30.push_back("1.06841715008998384033789050831892757796251622802680860264598247667384268519263E-24");
- if (coeffs_30.size() != 30) {
- std::cerr << "Fatal: array of size 30 does not have size 30" << std::endl;
- exit(1);
- }
+ if (coeffs_30.size() != 30)
+ throw std::logic_error("Fatal: array of size 30 does not have size 30");
+
std::vector<cln::cl_N> &coeffs_60 = coeffs[2];
coeffs_60.reserve(60);
/* sixty coefficients follow. */
@@ -1774,10 +1772,9 @@ lanczos_coeffs::lanczos_coeffs()
coeffs_60.push_back("1.022249951013180267209479446016461291488484443236553319305574600271584296178678167457933405768832443689762998392188667506451117069946568E-43");
coeffs_60.push_back("-1.158776990252157075591666544736990249102708476419363164106801472497162421792350234416969073422311477683246469337273059290064112071625785E-47");
coeffs_60.push_back("4.27222387142756413870104074160770434521893587460314314301300261552300727494374933435001642531897059406263033431558827297492879960920275E-49");
- if (coeffs_60.size() != 60) {
- std::cerr << "Fatal: array of size 60 does not have size 60" << std::endl;
- exit(1);
- }
+ if (coeffs_60.size() != 60)
+ throw std::logic_error("Fatal: array of size 60 does not have size 60");
+
std::vector<cln::cl_N> &coeffs_120 = coeffs[3];
coeffs_120.reserve(120);
/* 120 coefficients follow. */
@@ -1901,11 +1898,8 @@ lanczos_coeffs::lanczos_coeffs()
coeffs_120.push_back("4.5681983751743456413033268196376305093509590040595182930261094908859252761697530924655649930852283295534503341542929581967081012867692190108698698006237799801339418962091877730207560007839789937153876806052229193448161273005984514504886230869730232561E-94");
coeffs_120.push_back("-1.5943139155457706045530478744891549581317663177038648406493256399589001327414318955746453934207742828511041930090849236963271943244329753764497401819704943705370596846318480510254313447057477914171472190541408193443142906466279172123681623644325254209E-95");
coeffs_120.push_back("2.7319125666863032595604997603472305262880292377469053594326527505796348018540179196191192420176181194669607935656210005192217186286873953583571180312679155204061051208771126804209623533044988888808754656646355388901404252058383561064953226611421609762E-97");
- if (coeffs_120.size() != 120) {
- std::cerr << "Fatal: array of size 120 does not have size 120"
- << std::endl;
- exit(1);
- }
+ if (coeffs_120.size() != 120)
+ throw std::runtime_error("Fatal: array of size 120 does not have size 120");
}
--
1.4.4.3
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
URL: <http://www.ginac.de/pipermail/ginac-devel/attachments/20070118/40066ef6/attachment.sig>
More information about the GiNaC-devel
mailing list