Wrong BigInteger value (V8ScriptEngine)
seberoth opened this issue · 2 comments
seberoth commented
ClearScript: 7.4.1
.Net: 7
Hi,
I currently try to pass an uint64 from JS to a host method. After learning, that JS numbers doesn't work for that I tried using BigInteger.
But for some reason, the value which is passed to the host method isn't the one used in JS.
public class TestClass
{
public void TestMethod(BigInteger val)
{
// ...
// Call1: Expected: 18446744073709550590
// Got: 18446744073709549568
// Call2: Expected: 18446744073709550591
// Got: 18446744073709549568 (same as Call1)
// Call3: Expected: 18446744073709550592
// Got: 18446744073709551616
// Call4: Expected: 18446744073709550593
// Got: 18446744073709551616 (same as Call3)
// ...
}
}
internal class Program
{
static void Main(string[] args)
{
using (var engine = new V8ScriptEngine())
{
engine.AddHostObject("test", new TestClass());
engine.Execute("test.TestMethod(BigInt(18446744073709550590))");
engine.Execute("test.TestMethod(BigInt(18446744073709550591))");
engine.Execute("test.TestMethod(BigInt(18446744073709550592))");
engine.Execute("test.TestMethod(BigInt(18446744073709550593))");
}
}
}
seberoth commented
Nevermind, it was me -.-
Of course doesn't work to pass a number that big into the BigInt constructor. With qoutes it works.
ClearScriptLib commented
Hi @seberoth,
Thanks for the update. Note that you can also use BigInt
literals – e.g., 18446744073709550590n
to avoid parsing and explicit invocation of the BigInt
constructor.
Cheers!