From 610210450aec7eea9ee86f6b45004826c25e0945 Mon Sep 17 00:00:00 2001 From: toshinagata1964 Date: Fri, 9 Sep 2016 00:48:46 +0000 Subject: [PATCH] Creating cube file failed when very small electron density (<1e-100) appeared. Fixed. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@606 a2be9bc6-48de-4e38-9406-05402d4bc13c --- MolLib/Molecule.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MolLib/Molecule.c b/MolLib/Molecule.c index 90b4382..526edbf 100755 --- a/MolLib/Molecule.c +++ b/MolLib/Molecule.c @@ -11658,8 +11658,15 @@ MoleculeOutputCube(Molecule *mp, Int index, const char *fname, const char *comme /* On Windows, the "%e" format writes the exponent in 3 digits, but this is not standard. So we avoid using %e */ Double d = cp->dp[n++]; - int exponent = (int)floor(log10(fabs(d))); - Double base = d * pow(10, -1.0 * exponent); + int exponent; + Double base; + if (d >= -1.0e-90 && d <= 1.0e-90) { + exponent = 0; + base = 0.0; + } else { + exponent = (int)floor(log10(fabs(d))); + base = d * pow(10, -1.0 * exponent); + } fprintf(fp, " %8.5fe%+03d", base, exponent); /* fprintf(fp, " %12.5e", d); */ if (k == cp->nz - 1 || k % 6 == 5) -- 2.11.0