mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-04 05:33:50 +01:00 
			
		
		
		
	Adapts or removes tests that relied on creating durations that are now out of range. Adds new tests for maximum in-range and minimum out-of-range durations.
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
 | 
						||
// This code is governed by the BSD license found in the LICENSE file.
 | 
						||
 | 
						||
/*---
 | 
						||
esid: sec-temporal.duration.from
 | 
						||
description: >
 | 
						||
    Duration-like argument performs the range check with minimal floating point
 | 
						||
    precision loss
 | 
						||
features: [Temporal]
 | 
						||
---*/
 | 
						||
 | 
						||
// Based on a test case by André Bargull
 | 
						||
 | 
						||
const cases = [
 | 
						||
  [
 | 
						||
    {
 | 
						||
      milliseconds: 4503599627370497_000,  // ℝ(𝔽(4503599627370497000)) = 4503599627370497024
 | 
						||
      microseconds: 4503599627370495_000000,  // ℝ(𝔽(4503599627370495000000)) = 4503599627370494951424
 | 
						||
    },
 | 
						||
    // 4503599627370497024 / 1000 + 4503599627370494951424 / 1000000 is
 | 
						||
    // 9007199254740991.975424, which is below the limit of 2**53
 | 
						||
    "case where floating point inaccuracy brings total below limit, positive"
 | 
						||
  ],
 | 
						||
  [
 | 
						||
    {
 | 
						||
      milliseconds: -4503599627370497_000,
 | 
						||
      microseconds: -4503599627370495_000000,
 | 
						||
    },
 | 
						||
    "case where floating point inaccuracy brings total below limit, negative"
 | 
						||
  ],
 | 
						||
];
 | 
						||
 | 
						||
for (const [arg, descr] of cases) {
 | 
						||
  assert.sameValue(Temporal.Duration.compare(arg, arg), 0, descr);
 | 
						||
}
 |