From 660a070f4025d1b5dc4a9f6a57e3e425b77839e0 Mon Sep 17 00:00:00 2001 From: nick_battle Date: Tue, 14 Nov 2023 11:09:00 +0000 Subject: [PATCH] Real/rational tidy up for hp --- .../vdmj/tc/types/visitors/TCAnyValueGenerator.java | 11 +++++++---- .../java/com/fujitsu/vdmj/values/RationalValue.java | 5 +++++ .../main/java/com/fujitsu/vdmj/values/RealValue.java | 11 +---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/tc/types/visitors/TCAnyValueGenerator.java b/vdmj/src/main/java/com/fujitsu/vdmj/tc/types/visitors/TCAnyValueGenerator.java index cf914ccbc..be009b22a 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/tc/types/visitors/TCAnyValueGenerator.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/tc/types/visitors/TCAnyValueGenerator.java @@ -24,6 +24,9 @@ package com.fujitsu.vdmj.tc.types.visitors; +import java.math.BigDecimal; +import java.math.BigInteger; + import com.fujitsu.vdmj.tc.types.TCBasicType; import com.fujitsu.vdmj.tc.types.TCBooleanType; import com.fujitsu.vdmj.tc.types.TCBracketType; @@ -161,7 +164,7 @@ public Value caseNaturalOneType(TCNaturalOneType node, Object arg) { try { - return new NaturalOneValue(1); + return new NaturalOneValue(BigInteger.ONE); } catch (Exception e) { @@ -174,7 +177,7 @@ public Value caseNaturalType(TCNaturalType node, Object arg) { try { - return new NaturalValue(1); + return new NaturalValue(BigInteger.ONE); } catch (Exception e) { @@ -224,7 +227,7 @@ public Value caseRationalType(TCRationalType node, Object arg) { try { - return new RationalValue(0.0); + return new RationalValue(BigDecimal.ZERO); } catch (Exception e) { @@ -237,7 +240,7 @@ public Value caseRealType(TCRealType node, Object arg) { try { - return new RealValue(0.0); + return new RealValue(BigDecimal.ZERO); } catch (Exception e) { diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/values/RationalValue.java b/vdmj/src/main/java/com/fujitsu/vdmj/values/RationalValue.java index 24f22b6ad..2a726e131 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/values/RationalValue.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/values/RationalValue.java @@ -48,6 +48,11 @@ public RationalValue(BigInteger value) super(value); } + public RationalValue(double value) + { + super(new BigDecimal(value)); + } + @Override public String kind() { diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/values/RealValue.java b/vdmj/src/main/java/com/fujitsu/vdmj/values/RealValue.java index 57c0d1e40..6c0b7a222 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/values/RealValue.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/values/RealValue.java @@ -40,18 +40,9 @@ public class RealValue extends NumericValue { private static final long serialVersionUID = 1L; - public RealValue(BigDecimal value) throws Exception + public RealValue(BigDecimal value) { super(value); - -// if (Double.isInfinite(value)) -// { -// throw new Exception("Real is infinite"); -// } -// else if (Double.isNaN(value)) -// { -// throw new Exception("Real is NaN"); -// } } public RealValue(BigInteger value)