Code Search for Developers
 
 
  

ScientificDouble.java from MASE: Agile Software Engineering at Krugle


Show ScientificDouble.java syntax highlighted

// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.
package fit;

// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.

// Warning: not (yet) a general number usable in all calculations.

public class ScientificDouble extends Number implements Comparable
{
	protected double value;
	protected double precision;

	public ScientificDouble(double value)
	{
		this.value = value;
		this.precision = 0;
	}

	public static ScientificDouble valueOf(String s)
	{
		ScientificDouble result = new ScientificDouble(Double.parseDouble(s));
		result.precision = precision(s);
		return result;
	}

	public static ScientificDouble parse(String s)
	{
		return valueOf(s);
	}

	public static double precision(String s)
	{
		double value = Double.parseDouble(s);
		double bound = Double.parseDouble(tweak(s.trim()));
		return Math.abs(bound - value);
	}

	public static String tweak(String s)
	{
		int pos;
		if((pos = s.toLowerCase().indexOf("e")) >= 0)
		{
			return tweak(s.substring(0, pos)) + s.substring(pos);
		}
		if(s.indexOf(".") >= 0)
		{
			return s + "5";
		}
		return s + ".5";
	}

	public boolean equals(Object obj)
	{
		return compareTo(obj) == 0;
	}

	public int compareTo(Object obj)
	{
		double other = ((Number) obj).doubleValue();
		double diff = value - other;
		// System.out.println(value+" "+precision+" "+diff);
		if(diff < -precision) return -1;
		if(diff > precision) return 1;
		if(Double.isNaN(value) && Double.isNaN(other)) return 0;
		if(Double.isNaN(value)) return 1;
		if(Double.isNaN(other)) return -1;
		return 0;
	}

	public String toString()
	{
		return Double.toString(value);
	}

	public double doubleValue()
	{
		return value;
	}

	public float floatValue()
	{
		return (float) value;
	}

	public long longValue()
	{
		return (long) value;
	}

	public int intValue()
	{
		return (int) value;
	}
}




See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  exception/
    AmbiguousActionException.java
    AmbiguousNameFailureException.java
    BooleanMethodFitFailureException.java
    ClassIsNotFixtureException.java
    CouldNotLoadComponentFitFailureException.java
    CouldNotParseFitFailureException.java
    CycleException.java
    ExtraCellsFailureException.java
    FitFailureException.java
    FitFailureExceptionWithHelp.java
    FitMatcherException.java
    FitParseException.java
    FixtureException.java
    IgnoredException.java
    MissingCellsFailureException.java
    MissingFieldFitFailureException.java
    MissingMethodException.java
    MissingRowFailureException.java
    NestedTableExpected.java
    NoDefaultConstructorFixtureException.java
    NoSuchFieldFitFailureException.java
    NoSuchFixtureException.java
    NoSuchMethodFitFailureException.java
    RowWrongWidthException.java
    VoidMethodFitFailureException.java
  ActionFixture.java
  Binding.java
  ColumnFixture.java
  ColumnFixtureTest.java
  Comment.java
  Counts.java
  CountsTest.java
  FileRunner.java
  FitMatcher.java
  FitMatcherTest.java
  Fixture.java
  FixtureClass.java
  FixtureListener.java
  FixtureLoader.java
  FixtureLoaderTest.java
  FixtureName.java
  GracefulNamer.java
  GracefulNamerTest.java
  ImportFixture.java
  NullFixtureListener.java
  Parse.java
  ParseTest.java
  PrimitiveFixture.java
  RowFixture.java
  RowFixtureTest.java
  ScientificDouble.java
  ScientificDoubleTest.java
  SummaryFixture.java
  TestRunner.java
  TimedActionFixture.java
  TypeAdapter.java
  TypeAdapterTest.java
  WikiRunner.java