Browse Source

Double format method matching C.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@1847 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 16 years ago
parent
commit
d244f66b44
  1. 12
      prism/src/prism/PrismUtils.java

12
prism/src/prism/PrismUtils.java

@ -90,7 +90,7 @@ public class PrismUtils
// For two (near) zero values, return true, for just one, return false // For two (near) zero values, return true, for just one, return false
if (d1 < epsilonDouble) if (d1 < epsilonDouble)
return (d2 < epsilonDouble); return (d2 < epsilonDouble);
return ( Math.abs(d1 - d2) / d1 < epsilon);
return (Math.abs(d1 - d2) / d1 < epsilon);
} }
/** /**
@ -180,8 +180,18 @@ public class PrismUtils
private static DecimalFormat formatterDouble2dp = new DecimalFormat("#0.00"); private static DecimalFormat formatterDouble2dp = new DecimalFormat("#0.00");
/**
* Format a double, as would be done by printf's %.12g
*/
public static String formatDouble(double d)
{
// Note that we have to tweak this since Java do it quite like C.
return String.format("%.12g", d).replaceFirst("\\.?0+(e|$)", "$1");
}
/** /**
* Format a double. * Format a double.
* TODO: fix me (precision ignored, re-use above code instead)
*/ */
public static String formatDouble(int precision, double d) public static String formatDouble(int precision, double d)
{ {

Loading…
Cancel
Save