Skip to content

Commit

Permalink
Modified Sqrt to pass all acid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed Jun 9, 2021
1 parent 67d4a94 commit 837322c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Yolol/Execution/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,12 @@ public Number Sqrt()
if (this >= 9223372036854775)
return MinValue;

//return FromRaw((long)(Math.Sqrt(1000 * RawValue)));
//return FromRaw((long)(Math.Sqrt(RawValue) * 31.62277660168379f));
var converted = (double)this;
var result = Math.Sqrt(converted);

return (Number)Math.Sqrt((double)this);
var epsilon = result < 0 ? -0.00005 : 0.00005;

return (Number)(epsilon + result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
2 changes: 1 addition & 1 deletion Yolol/Yolol.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://github.com/martindevans/Yolol</PackageProjectUrl>
<RepositoryUrl>https://github.com/martindevans/Yolol</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>12.0.0</Version>
<Version>13.0.0</Version>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
4 changes: 2 additions & 2 deletions YololEmulator.Tests/Scripts/Acid/Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void SqrtF()
"x=sqrt 1000002"
);

Assert.AreEqual("1000", ms.GetVariable("x").Value.Number.ToString());
Assert.AreEqual("1000.001", ms.GetVariable("x").Value.Number.ToString());
}

[TestMethod]
Expand Down Expand Up @@ -116,7 +116,7 @@ public void SqrtJ()
// "x=(sqrt 7) y=2.645 if x!=y then goto19 end n++ ",
// "x=(sqrt 32199) y=179.440 if x!=y then goto19 end n++ ",
// "x=(sqrt 1000001) y=1000 if x!=y then goto19 end n++ ",
// "x=(sqrt 1000002) y=1000 if x!=y then goto19 end n++ ",
// "x=(sqrt 1000002) y=1000.001 if x!=y then goto19 end n++ ",
// "x=sqrt 9223372036854775.807 y=-9223372036854775.808 n++ goto19/(x!=y)",
// "x=(sqrt -3) y=-9223372036854775.808 if x!=y then goto19 end n++ ",
// "x=sqrt 9223372036854775 y=-9223372036854775.808 n++ goto19/(x!=y) ",
Expand Down

0 comments on commit 837322c

Please sign in to comment.