1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

Infinite values of the floating point types.

This commit is contained in:
Mikhail Khodjaiants 2003-06-05 21:18:25 +00:00
parent 1d3ef1c353
commit 4890f5b3c1
9 changed files with 112 additions and 48 deletions

View file

@ -1,3 +1,8 @@
2003-06-05 Mikhail Khodjaiants
Core support of infinite values of the floating point types.
* ICVariable.java
* CVariable.java
2003-06-05 Mikhail Khodjaiants
Renamed the 'computeDetail' method of the 'ICValue' interface to 'evaluateAsExpression'.
* ICValue.java

View file

@ -38,6 +38,10 @@ public interface ICVariable extends IVariable
boolean isNaN();
boolean isPositiveInfinity();
boolean isNegativeInfinity();
boolean isPointer();
String getQualifiedName() throws DebugException;

View file

@ -693,6 +693,56 @@ public abstract class CVariable extends CDebugElement
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isNegativeInfinity()
*/
public boolean isNegativeInfinity()
{
try
{
ICDIValue value = getCDIVariable().getValue();
if ( value instanceof ICDIDoubleValue )
{
double dbl = ((ICDIDoubleValue)value).doubleValue();
return ( Double.isInfinite( dbl ) && Double.NEGATIVE_INFINITY == dbl );
}
if ( value instanceof ICDIFloatValue )
{
float flt = ((ICDIFloatValue)value).floatValue();
return ( Float.isInfinite( flt ) && Float.NEGATIVE_INFINITY == flt );
}
}
catch( CDIException e )
{
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isPositiveInfinity()
*/
public boolean isPositiveInfinity()
{
try
{
ICDIValue value = getCDIVariable().getValue();
if ( value instanceof ICDIDoubleValue )
{
double dbl = ((ICDIDoubleValue)value).doubleValue();
return ( Double.isInfinite( dbl ) && Double.POSITIVE_INFINITY == dbl );
}
if ( value instanceof ICDIFloatValue )
{
float flt = ((ICDIFloatValue)value).floatValue();
return ( Float.isInfinite( flt ) && Float.POSITIVE_INFINITY == flt );
}
}
catch( CDIException e )
{
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isFloatingPointType()
*/

View file

@ -1,3 +1,9 @@
2003-06-05 Mikhail Khodjaiants
gdb/mi support of infinite values of the floating point types.
* DoubleValue.java
* FloatingPointValue.java
* FloatValue.java
2003-06-05 Mikhail Khodjaiants
Removed the redundant methods from the 'ICDIFloatingPointValue' interface.
* src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java

View file

@ -5,7 +5,6 @@
package org.eclipse.cdt.debug.mi.core.cdi.model.type;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue;
import org.eclipse.cdt.debug.mi.core.cdi.model.Variable;
@ -19,21 +18,4 @@ public class DoubleValue extends FloatingPointValue implements ICDIDoubleValue {
public DoubleValue(Variable v) {
super(v);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue#isNaN()
*/
public boolean isNaN() {
// Identify this value as Not-a-Number if parsing fails.
try {
Double.parseDouble( getValueString() );
}
catch (NumberFormatException e) {
return true;
}
catch (CDIException e) {
return true;
}
return false;
}
}

View file

@ -5,7 +5,6 @@
package org.eclipse.cdt.debug.mi.core.cdi.model.type;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue;
import org.eclipse.cdt.debug.mi.core.cdi.model.Variable;
@ -19,21 +18,4 @@ public class FloatValue extends FloatingPointValue implements ICDIFloatValue {
public FloatValue(Variable v) {
super(v);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue#isNaN()
*/
public boolean isNaN() {
// Identify this value as Not-a-Number if parsing fails.
try {
Float.parseFloat( getValueString() );
}
catch (NumberFormatException e) {
return true;
}
catch (CDIException e) {
return true;
}
return false;
}
}

View file

@ -26,13 +26,16 @@ public abstract class FloatingPointValue extends Value implements ICDIFloatingPo
*/
public double doubleValue() throws CDIException {
double result = 0;
if ( isNaN() )
if (isNaN())
result = Double.NaN;
else if (isNegativeInfinity())
result = Double.NEGATIVE_INFINITY;
else if (isPositiveInfinity())
result = Double.POSITIVE_INFINITY;
else {
try {
result = Double.parseDouble( getValueString() );
}
catch (NumberFormatException e) {
result = Double.parseDouble(getValueString());
} catch (NumberFormatException e) {
}
}
return result;
@ -43,20 +46,33 @@ public abstract class FloatingPointValue extends Value implements ICDIFloatingPo
*/
public float floatValue() throws CDIException {
float result = 0;
if ( isNaN() )
if (isNaN())
result = Float.NaN;
else if (isNegativeInfinity())
result = Float.NEGATIVE_INFINITY;
else if (isPositiveInfinity())
result = Float.POSITIVE_INFINITY;
else {
try {
result = Float.parseFloat( getValueString() );
}
catch (NumberFormatException e) {
result = Float.parseFloat(getValueString());
} catch (NumberFormatException e) {
}
}
return result;
}
private boolean isPositiveInfinity() throws CDIException {
String valueString = getValueString();
return (valueString != null) ? valueString.indexOf("inf") != -1 : false;
}
private boolean isNegativeInfinity() throws CDIException {
String valueString = getValueString();
return (valueString != null) ? valueString.indexOf("-inf") != -1 : false;
}
private boolean isNaN() throws CDIException {
String valueString = getValueString();
return ( valueString != null ) ? valueString.indexOf( "nan" ) != -1 : false;
return (valueString != null) ? valueString.indexOf("nan") != -1 : false;
}
}

View file

@ -1,3 +1,7 @@
2003-06-05 Mikhail Khodjaiants
UI support of infinite values of the floating point types.
* CDTDebugModelPresentation.java
2003-06-05 Mikhail Khodjaiants
Evaluate expressions of detail panel asynchronously.
* CDTValueDetailProvider.java

View file

@ -565,14 +565,29 @@ public class CDTDebugModelPresentation extends LabelProvider
label.append( ']' );
}
}
else if ( !((ICVariable)var).isStructure() && value.getValueString() != null )
else if ( ((ICVariable)var).isCharacter() && value.getValueString() != null )
{
String valueString = value.getValueString().trim();
if ( valueString.length() == 0 && ((ICVariable)var).isCharacter() )
if ( valueString.length() == 0 )
valueString = ".";
label.append( "= " );
label.append( valueString );
}
else if ( ((ICVariable)var).isFloatingPointType() && value.getValueString() != null )
{
String valueString = value.getValueString().trim();
if ( ((ICVariable)var).isNaN() )
valueString = "NAN";
if ( ((ICVariable)var).isPositiveInfinity() )
valueString = "Infinity";
if ( ((ICVariable)var).isNegativeInfinity() )
valueString = "-Infinity";
label.append( "= " );
label.append( valueString );
}
else if ( !((ICVariable)var).isStructure() && value.getValueString() != null )
{
String valueString = value.getValueString().trim();
if ( valueString.length() > 0 )
{
label.append( "= " );