Re: Infinite Interval
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Joseph Koshakow <koshy44@gmail.com>,
"Gregory Stark (as CFM)" <stark.cfm@gmail.com>, jian he <jian.universality@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-03-28T13:43:54Z
Lists: pgsql-hackers
Attachments
- float_inf.c (text/x-csrc)
On Sun, Mar 26, 2023 at 1:28 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> I think you can take it as read that simple C test programs on modern
> platforms will exhibit IEEE-compliant handling of float infinities.
>
For the record, I tried the attached. It gives a warning at compilation time.
$gcc float_inf.c
float_inf.c: In function ‘main’:
float_inf.c:10:17: warning: division by zero [-Wdiv-by-zero]
10 | float inf = 1.0/0;
| ^
float_inf.c:11:20: warning: division by zero [-Wdiv-by-zero]
11 | float n_inf = -1.0/0;
| ^
$ ./a.out
inf = inf
-inf = -inf
inf + inf = inf
inf + -inf = -nan
-inf + inf = -nan
-inf + -inf = -inf
inf - inf = -nan
inf - -inf = inf
-inf - inf = -inf
-inf - -inf = -nan
float 0.0 equals 0.0
float 1.0 equals 1.0
5.0 * inf = inf
5.0 * - inf = -inf
5.0 / inf = 0.000000
5.0 / - inf = -0.000000
inf / 5.0 = inf
- inf / 5.0 = -inf
The changes in the patch are compliant with the observations above.
--
Best Wishes,
Ashutosh Bapat
Commits
-
Support +/- infinity in the interval data type.
- 519fc1bd9e9d 17.0 landed
-
Avoid integer overflow hazard in interval_time().
- 3850d4dec1d9 17.0 landed
-
Guard against overflow in make_interval().
- b2d55447a563 17.0 landed
-
Fix minmax-multi on infinite date/timestamp values
- 8da86d62a112 17.0 cited
-
Optimize various aggregate deserialization functions, take 2
- 0c882a298881 17.0 cited
-
Remove dead code in DecodeInterval()
- d6d1430f4043 17.0 cited
-
Accept "+infinity" in date and timestamp[tz] input.
- 2ceea5adb026 16.0 cited
-
Fix overflow hazards in interval input and output conversions.
- e39f99046710 15.0 cited