pitrou commented on code in PR #379:
URL: https://github.com/apache/arrow-js/pull/379#discussion_r2792172430


##########
test/unit/vector/interval-month-day-nano-tests.ts:
##########
@@ -77,4 +78,42 @@ describe(`MonthDayNanoIntervalVector`, () => {
         expect(vec.get(0)).toStrictEqual(array);
         expect(toIntervalMonthDayNanoObjects(vec.get(0), 
false)).toStrictEqual([{ ...EMPTY_INTERVAL_MONTH_DAY_NANO_OBJECT, ...obj }]);
     });
+
+    test(`Unsafe integer nanoseconds represented as bigint roundtrip 
correctly`, () => {
+        const samples = [
+            '-390122861233460600',
+            '6684525287992311000'
+        ];
+        for (const sample of samples) {
+            const nanoseconds = BigInt(sample);
+            const obj: Partial<IntervalMonthDayNanoObject> = { nanoseconds };

Review Comment:
   Is the right field being populated here, or should that be `{ nanoseconds : 
nanoseconds }`? Sorry, not a TS developer.



##########
src/util/interval.ts:
##########
@@ -46,7 +46,11 @@ export function toIntervalMonthDayNanoInt32Array(objects: 
Partial<IntervalMonthD
         data[ai++] = interval['days'] ?? 0;
         const nanoseconds = interval['nanoseconds'];
         if (nanoseconds) {
-            const ns = BigInt(nanoseconds);
+            // Avoid BigInt(number) for unsafe integers, which can embed
+            // IEEE-754 rounding before conversion.

Review Comment:
   Is this still any useful? I don't understand why 
```BigInt(`${nanoseconds}`)``` would be any better than `BigInt(nanoseconds)`. 
If the data is already rounded, we cannot restore the lost precision...
   
   What we could do is call `nanoseconds.isSafeInteger` and warn/assert if it 
returns false?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to