Skip to content

Draft: Use 128-bit floats instead of BigInts #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions lib/bigintmath.ts

This file was deleted.

11 changes: 6 additions & 5 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { TimeDuration } from './timeduration';
import type { Temporal } from '..';
import type { DurationParams as Params, DurationReturn as Return } from './internaltypes';
import JSBI from 'jsbi';

export class Duration implements Temporal.Duration {
constructor(
Expand Down Expand Up @@ -270,8 +269,10 @@ export class Duration implements Temporal.Duration {
let internalDuration = ES.ToInternalDurationRecordWith24HourDays(this);
if (smallestUnit === 'day') {
// First convert time units up to days
const { quotient, remainder } = internalDuration.time.divmod(ES.DAY_NANOS);
let days = internalDuration.date.days + quotient + ES.TotalTimeDuration(remainder, 'day');
const div = internalDuration.time.totalNs.fdiv(ES.DAY_NANOS);
const quotient = div.toInt();
const fractionalDays = div.fadd(-quotient).toNumber();
let days = internalDuration.date.days + quotient + fractionalDays;
days = ES.RoundNumberToIncrement(days, roundingIncrement, roundingMode);
const dateDuration = { years: 0, months: 0, weeks: 0, days };
internalDuration = ES.CombineDateAndTimeDuration(dateDuration, TimeDuration.ZERO);
Expand Down Expand Up @@ -416,7 +417,7 @@ export class Duration implements Temporal.Duration {

const after1 = ES.AddZonedDateTime(epochNs, timeZone, calendar, duration1);
const after2 = ES.AddZonedDateTime(epochNs, timeZone, calendar, duration2);
return ES.ComparisonResult(JSBI.toNumber(JSBI.subtract(after1, after2)));
return ES.ComparisonResult(after1.sub(after2).toNumber());
}

let d1 = duration1.date.days;
Expand All @@ -430,7 +431,7 @@ export class Duration implements Temporal.Duration {
}
const timeDuration1 = duration1.time.add24HourDays(d1);
const timeDuration2 = duration2.time.add24HourDays(d2);
return timeDuration1.cmp(timeDuration2);
return timeDuration1.totalNs.cmp(timeDuration2.totalNs);
}
[Symbol.toStringTag]!: 'Temporal.Duration';
}
Expand Down
Loading