Re: [whatwg/webidl] Intent to use BigInt/numeric union in WebNN (Issue #1388)

Howdy Anne. We're looking at a union of `(double and BigInt)`, where `double` (float64) is large enough to handle any *floating* point constant (float16, float32, float64), and `BigInt` is large enough to handle any *integer* constant (int8, uint8, int32, uint32, int64, uint64). Are you suggesting a union of `(double or long long)`?

Using *only* double gets us most of the way, yes, but it's the endpoints that concern me. We want JS to be able to accurately map the full range of int64/uint64 tensors (e.g. `numpy.uint64`, `tensorflow.uint64`, `ONNX.TensorProto.DataType.UINT64`, `BNNSDataTypeUInt64`, `MPSDataType.uInt64`, `mx.uint64`, `ov::element::Type_t::u64`...), and yeah, most values past 2^52 likely don't need exact precision, but for cases like sentinel values and masks (e.g. `0xFFFFFFFFFFFFFFFF`), we'd have a challenge representing them via a double. You would think that passing a really large double like 1.8446744073709552e+19 might map cleanly to 0xFFFFFFFFFFFFFFFF, but you get varying results depending on the FPU logic. Even with C++ on my x64 machine, if you attempt to `static_cast` a double like 1.8446744073709552e+19 to `uint64_t`, you get back a surprising answer of 0x8000000000000000 instead of 0xFFFFFFFFFFFFFFFF, and I don't know what happens on ARM/M1.

For `long long` (https://webidl.spec.whatwg.org/#idl-long-long), is `BigInt` *the* way to express int64/uint64 via JS? Thanks.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1388#issuecomment-1970161413
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1388/1970161413@github.com>

Received on Thursday, 29 February 2024 00:28:28 UTC