Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1bc2d54

Browse files
committed
Localize our dependencies on the way to create NAN or INFINITY.
Per recent proposal to pghackers.
1 parent89ab5c4 commit1bc2d54

File tree

9 files changed

+106
-81
lines changed

9 files changed

+106
-81
lines changed

‎contrib/seg/seg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ seg_cmp(SEG * a, SEG * b)
755755
* a->lower == b->lower, so consider type of boundary.
756756
*
757757
* A '-' lower bound is < any other kind (this could only be relevant if
758-
* -HUGE is used as a regular data value). A '<' lower bound is < any
758+
* -HUGE_VAL is used as a regular data value). A '<' lower bound is < any
759759
* other kind except '-'. A '>' lower bound is > any other kind.
760760
*/
761761
if (a->l_ext!=b->l_ext)
@@ -813,7 +813,7 @@ seg_cmp(SEG * a, SEG * b)
813813
* a->upper == b->upper, so consider type of boundary.
814814
*
815815
* A '-' upper bound is > any other kind (this could only be relevant if
816-
*HUGE is used as a regular data value). A '<' upper bound is < any
816+
*HUGE_VAL is used as a regular data value). A '<' upper bound is < any
817817
* other kind. A '>' upper bound is > any other kind except '-'.
818818
*/
819819
if (a->u_ext!=b->u_ext)

‎contrib/seg/segparse.y

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#include<math.h>
77

88
#include"segdata.h"
9-
10-
#ifdef __CYGWIN__
11-
#defineHUGE HUGE_VAL
12-
#endif/* __CYGWIN__*/
139

1410
#undef yylex/* falure to redefine yylex will result in calling the*/
1511
#defineyylex seg_yylex/* wrong scanner when running inside postgres backend*/
@@ -86,15 +82,15 @@ range:
8682
|
8783
boundaryRANGE {
8884
((SEG *)result)->lower =$1.val;
89-
((SEG *)result)->upper =HUGE;
85+
((SEG *)result)->upper =HUGE_VAL;
9086
((SEG *)result)->l_sigd =$1.sigd;
9187
((SEG *)result)->u_sigd =0;
9288
((SEG *)result)->l_ext = ($1.ext ?$1.ext :'\0' );
9389
((SEG *)result)->u_ext ='-';
9490
}
9591
|
9692
RANGEboundary {
97-
((SEG *)result)->lower = -HUGE;
93+
((SEG *)result)->lower = -HUGE_VAL;
9894
((SEG *)result)->upper =$2.val;
9995
((SEG *)result)->l_sigd =0;
10096
((SEG *)result)->u_sigd =$2.sigd;

‎src/backend/port/qnx4/isnan.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/port/qnx4/isnan.c,v 1.4 2003/11/29 19:51:54 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/port/qnx4/isnan.c,v 1.5 2004/03/15 03:29:22 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include"c.h"
1616

17-
unsignedchar__nan[8]=__nan_bytes;
17+
#include<math.h>
18+
19+
#ifndef__nan_bytes
20+
#define__nan_bytes{ 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }
21+
#endif/* __nan_bytes */
22+
23+
staticunsignedchar__nan[8]=__nan_bytes;
1824

1925
int
2026
isnan(doubledsrc)
2127
{
22-
return!memcmp(&dsrc,&NAN,sizeof(double));
28+
returnmemcmp(&dsrc,__nan,sizeof(double))==0;
2329
}

‎src/backend/utils/adt/float.c

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.100 2004/03/14 05:22:52 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.101 2004/03/15 03:29:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -54,9 +54,8 @@
5454

5555
#include<ctype.h>
5656
#include<errno.h>
57-
#include<float.h>/* faked on sunos4 */
57+
#include<float.h>
5858
#include<math.h>
59-
6059
#include<limits.h>
6160
/* for finite() on Solaris */
6261
#ifdefHAVE_IEEEFP_H
@@ -70,19 +69,11 @@
7069
#include"utils/builtins.h"
7170

7271

73-
#ifndefHAVE_CBRT
74-
staticdoublecbrt(doublex);
75-
#endif/* HAVE_CBRT */
76-
7772
#ifndefM_PI
7873
/* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
7974
#defineM_PI 3.14159265358979323846
8075
#endif
8176

82-
#ifndefNAN
83-
#defineNAN(0.0/0.0)
84-
#endif
85-
8677
#ifndefSHRT_MAX
8778
#defineSHRT_MAX 32767
8879
#endif
@@ -109,9 +100,78 @@ intextra_float_digits = 0;/* Added to DBL_DIG or FLT_DIG */
109100

110101
staticvoidCheckFloat4Val(doubleval);
111102
staticvoidCheckFloat8Val(doubleval);
112-
staticintis_infinite(doubleval);
113103
staticintfloat4_cmp_internal(float4a,float4b);
114104
staticintfloat8_cmp_internal(float8a,float8b);
105+
#ifndefHAVE_CBRT
106+
staticdoublecbrt(doublex);
107+
#endif/* HAVE_CBRT */
108+
109+
110+
/*
111+
* Routines to provide reasonably platform-independent handling of
112+
* infinity and NaN. We assume that isinf() and isnan() are available
113+
* and work per spec. (On some platforms, we have to supply our own;
114+
* see src/port.) However, generating an Infinity or NaN in the first
115+
* place is less well standardized; pre-C99 systems tend not to have C99's
116+
* INFINITY and NAN macros. We centralize our workarounds for this here.
117+
*/
118+
119+
double
120+
get_float8_infinity(void)
121+
{
122+
#ifdefINFINITY
123+
/* C99 standard way */
124+
return (double)INFINITY;
125+
#else
126+
/*
127+
* On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
128+
* largest normal double. We assume forcing an overflow will get us
129+
* a true infinity.
130+
*/
131+
return (double) (HUGE_VAL*HUGE_VAL);
132+
#endif
133+
}
134+
135+
float
136+
get_float4_infinity(void)
137+
{
138+
#ifdefINFINITY
139+
/* C99 standard way */
140+
return (float)INFINITY;
141+
#else
142+
/*
143+
* On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
144+
* largest normal double. We assume forcing an overflow will get us
145+
* a true infinity.
146+
*/
147+
return (float) (HUGE_VAL*HUGE_VAL);
148+
#endif
149+
}
150+
151+
double
152+
get_float8_nan(void)
153+
{
154+
#ifdefNAN
155+
/* C99 standard way */
156+
return (double)NAN;
157+
#else
158+
/* Assume we can get a NAN via zero divide */
159+
return (double) (0.0 /0.0);
160+
#endif
161+
}
162+
163+
float
164+
get_float4_nan(void)
165+
{
166+
#ifdefNAN
167+
/* C99 standard way */
168+
return (float)NAN;
169+
#else
170+
/* Assume we can get a NAN via zero divide */
171+
return (float) (0.0 /0.0);
172+
#endif
173+
}
174+
115175

116176
/*
117177
* Returns -1 if 'val' represents negative infinity, 1 if 'val'
@@ -120,7 +180,7 @@ static intfloat8_cmp_internal(float8 a, float8 b);
120180
* does not specify that isinf() needs to distinguish between positive
121181
* and negative infinity.
122182
*/
123-
staticint
183+
int
124184
is_infinite(doubleval)
125185
{
126186
intinf=isinf(val);
@@ -134,6 +194,7 @@ is_infinite(double val)
134194
return-1;
135195
}
136196

197+
137198
/*
138199
* check to see if a float4 val is outside of the FLOAT4_MIN,
139200
* FLOAT4_MAX bounds.
@@ -237,17 +298,17 @@ float4in(PG_FUNCTION_ARGS)
237298
*/
238299
if (strncasecmp(num,"NaN",3)==0)
239300
{
240-
val=NAN;
301+
val=get_float4_nan();
241302
endptr=num+3;
242303
}
243304
elseif (strncasecmp(num,"Infinity",8)==0)
244305
{
245-
val=HUGE_VAL;
306+
val=get_float4_infinity();
246307
endptr=num+8;
247308
}
248309
elseif (strncasecmp(num,"-Infinity",9)==0)
249310
{
250-
val=-HUGE_VAL;
311+
val=-get_float4_infinity();
251312
endptr=num+9;
252313
}
253314
else
@@ -402,17 +463,17 @@ float8in(PG_FUNCTION_ARGS)
402463
*/
403464
if (strncasecmp(num,"NaN",3)==0)
404465
{
405-
val=NAN;
466+
val=get_float8_nan();
406467
endptr=num+3;
407468
}
408469
elseif (strncasecmp(num,"Infinity",8)==0)
409470
{
410-
val=HUGE_VAL;
471+
val=get_float8_infinity();
411472
endptr=num+8;
412473
}
413474
elseif (strncasecmp(num,"-Infinity",9)==0)
414475
{
415-
val=-HUGE_VAL;
476+
val=-get_float8_infinity();
416477
endptr=num+9;
417478
}
418479
else

‎src/backend/utils/adt/numeric.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.71 2004/02/04 01:11:47 neilc Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.72 2004/03/15 03:29:22 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -42,15 +42,6 @@
4242
*/
4343

4444

45-
/* ----------
46-
* Local definitions
47-
* ----------
48-
*/
49-
#ifndefNAN
50-
#defineNAN(0.0/0.0)
51-
#endif
52-
53-
5445
/* ----------
5546
* Local data types
5647
*
@@ -1790,7 +1781,7 @@ numeric_float8(PG_FUNCTION_ARGS)
17901781
Datumresult;
17911782

17921783
if (NUMERIC_IS_NAN(num))
1793-
PG_RETURN_FLOAT8(NAN);
1784+
PG_RETURN_FLOAT8(get_float8_nan());
17941785

17951786
tmp=DatumGetCString(DirectFunctionCall1(numeric_out,
17961787
NumericGetDatum(num)));
@@ -1811,7 +1802,7 @@ numeric_float8_no_overflow(PG_FUNCTION_ARGS)
18111802
doubleval;
18121803

18131804
if (NUMERIC_IS_NAN(num))
1814-
PG_RETURN_FLOAT8(NAN);
1805+
PG_RETURN_FLOAT8(get_float8_nan());
18151806

18161807
val=numeric_to_double_no_overflow(num);
18171808

@@ -1850,7 +1841,7 @@ numeric_float4(PG_FUNCTION_ARGS)
18501841
Datumresult;
18511842

18521843
if (NUMERIC_IS_NAN(num))
1853-
PG_RETURN_FLOAT4((float4)NAN);
1844+
PG_RETURN_FLOAT4(get_float4_nan());
18541845

18551846
tmp=DatumGetCString(DirectFunctionCall1(numeric_out,
18561847
NumericGetDatum(num)));

‎src/backend/utils/adt/timestamp.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.100 2004/03/05 02:41:14 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.101 2004/03/15 03:29:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -20,10 +20,6 @@
2020
#include<errno.h>
2121
#include<float.h>
2222
#include<limits.h>
23-
/* for finite() on Solaris */
24-
#ifdefHAVE_IEEEFP_H
25-
#include<ieeefp.h>
26-
#endif
2723

2824
#include"access/hash.h"
2925
#include"access/xact.h"

‎src/include/port/qnx4.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,8 @@
99

1010
#definestrncasecmp strnicmp
1111

12-
#ifndefNAN
13-
#ifndef__nan_bytes
14-
#define__nan_bytes{ 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }
15-
#endif/* __nan_bytes */
16-
externunsignedchar__nan[8];
17-
18-
#defineNAN (*(const double *) __nan)
19-
#endif/* NAN */
20-
2112
typedefu_shortushort;
2213

2314
externintisnan(doubledsrc);
24-
2515
externlongrandom(void);
2616
externvoidsrandom(unsignedintseed);

‎src/include/port/solaris.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/solaris.h,v 1.10 2003/12/23 03:31:30 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/solaris.h,v 1.11 2004/03/15 03:29:22 tgl Exp $ */
22

33
/*
44
* Sort this out for all operating systems some time. The __xxx
@@ -35,24 +35,3 @@
3535
#defineBYTE_ORDER LITTLE_ENDIAN
3636
#endif
3737
#endif
38-
39-
40-
#ifndefNAN
41-
42-
#if defined(__GNUC__)&& defined(__i386__)
43-
44-
#ifndef__nan_bytes
45-
#define__nan_bytes { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }
46-
#endif
47-
48-
#defineNAN \
49-
(__extension__ ((union { unsigned char __c[8]; double __d; }) \
50-
{ __nan_bytes }).__d)
51-
52-
#else
53-
/* not GNUC and i386 */
54-
55-
#defineNAN (0.0/0.0)
56-
#endif/* GCC. */
57-
58-
#endif/* not NAN */

‎src/include/utils/builtins.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.234 2004/02/03 08:29:57 joe Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.235 2004/03/15 03:29:22 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -240,6 +240,12 @@ extern Datum bttext_pattern_cmp(PG_FUNCTION_ARGS);
240240
/* float.c */
241241
externDLLIMPORTintextra_float_digits;
242242

243+
externdoubleget_float8_infinity(void);
244+
externfloatget_float4_infinity(void);
245+
externdoubleget_float8_nan(void);
246+
externfloatget_float4_nan(void);
247+
externintis_infinite(doubleval);
248+
243249
externDatumfloat4in(PG_FUNCTION_ARGS);
244250
externDatumfloat4out(PG_FUNCTION_ARGS);
245251
externDatumfloat4recv(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp