Skip to content
18 changes: 14 additions & 4 deletions Source/AbstractInterpretation/IntervalDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static Expr NumberToExpr(BigInteger n, Type ty)
}
else if (ty.IsFloat)
{
return Expr.Literal(BaseTypes.BigFloat.FromBigInt(n, ty.FloatExponent, ty.FloatSignificand));
return Expr.Literal(BaseTypes.BigFloat.FromBigInt(n, ty.FloatSignificand, ty.FloatExponent));
}
else
{
Expand Down Expand Up @@ -958,9 +958,19 @@ public override Expr VisitLiteralExpr(LiteralExpr node)
}
else if (node.Val is BigFloat)
{
((BigFloat) node.Val).FloorCeiling(out var floor, out var ceiling);
Lo = floor;
Hi = ceiling;
var bf = (BigFloat) node.Val;
if (bf.IsNaN || bf.IsInfinity)
{
// NaN and infinity have no meaningful integer bounds
Lo = null;
Hi = null;
}
else
{
bf.FloorCeiling(out var floor, out var ceiling);
Lo = floor;
Hi = ceiling;
}
}
else if (node.Val is bool)
{
Expand Down
1,384 changes: 893 additions & 491 deletions Source/BaseTypes/BigFloat.cs

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Source/Core/BoogiePL.atg
Original file line number Diff line number Diff line change
Expand Up @@ -1977,11 +1977,9 @@ Float<out BigFloat n>
(
float (. s = t.val; .)
)
(. try {
n = BigFloat.FromString(s);
} catch (FormatException e) {
this.SemErr("incorrectly formatted floating point, " + e.Message);
n = BigFloat.ZERO;
(. if (!BigFloat.TryParseExact(s, out n)) {
this.SemErr("incorrectly formatted floating point");
n = BigFloat.CreateZero(false, 24, 8);
}
.)
.
Expand Down
8 changes: 3 additions & 5 deletions Source/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2473,11 +2473,9 @@ void Float(out BigFloat n) {
string s = "";
Expect(7);
s = t.val;
try {
n = BigFloat.FromString(s);
} catch (FormatException e) {
this.SemErr("incorrectly formatted floating point, " + e.Message);
n = BigFloat.ZERO;
if (!BigFloat.TryParseExact(s, out n)) {
this.SemErr("incorrectly formatted floating point");
n = BigFloat.CreateZero(false, 24, 8);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Target framework and package configuration -->
<PropertyGroup>
<Version>3.5.4</Version>
<Version>3.5.5</Version>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Boogie</Authors>
Expand Down
33 changes: 31 additions & 2 deletions Source/Model/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ An instance of the Model class represents a single model returned from the SMT s
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.BaseTypes;

namespace Microsoft.Boogie
{
Expand All @@ -44,7 +45,8 @@ public enum ElementKind
Boolean,
Uninterpreted,
Array,
DataValue
DataValue,
Float
}

public abstract class Element
Expand Down Expand Up @@ -187,6 +189,26 @@ public override string ToString()
}
}

public class Float : Element
{
internal Float(Model p, string n) : base(p)
{
Literal = n;
}

public readonly string Literal;

public override ElementKind Kind
{
get { return ElementKind.Float; }
}

public override string ToString()
{
return Literal;
}
}

public class Boolean : Element
{
public bool Value;
Expand Down Expand Up @@ -716,7 +738,14 @@ public Element ConstructElement(string name)
}
else
{
return null;
// Try parsing as BigFloat
try {
var _ = BigFloat.FromString(name);
return new Float(this, name);
} catch {
// Not a valid number at all
return null;
}
}
}
else if (name[0] == '*' || name.StartsWith("val!") || name.Contains("!val!"))
Expand Down
1 change: 1 addition & 0 deletions Source/Model/Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BaseTypes\BaseTypes.csproj" />
<ProjectReference Include="..\CodeContractsExtender\CodeContractsExtender.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Source/Provers/SMTLib/SMTLibInteractiveTheoremProver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public override async Task<object> Evaluate(VCExpr expr)
String specialValue = resp.Arguments[0].ToString();
int expSize = int.Parse(resp.Arguments[1].ToString());
int sigSize = int.Parse(resp.Arguments[2].ToString());
return new BaseTypes.BigFloat(specialValue, sigSize, expSize);
return BaseTypes.BigFloat.CreateSpecialFromString(specialValue, sigSize, expSize);
}

var ary = ParseArrayFromProverResponse(resp);
Expand Down
2 changes: 1 addition & 1 deletion Source/Provers/SMTLib/SMTLibLineariser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public bool Visit(VCExprLiteral node, LineariserOptions options)
else if (node is VCExprFloatLit)
{
BigFloat lit = ((VCExprFloatLit) node).Val;
wr.Write("(" + lit.ToBVString() + ")");
wr.Write("(" + lit.ToSMTLibString() + ")");
}
else if (node is VCExprRModeLit)
{
Expand Down
Loading
Loading