PostgreSQL Source Code: src/backend/utils/adt/float.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

17#include <ctype.h>

19#include <math.h>

20#include <limits.h>

21

28#include "utils/fmgrprotos.h"

30

31

32

33

34

35

36

37

38

39

41

42

51

52

53

54

55

56

57

58

59

60

71

72

73static double sind_q1(double x);

74static double cosd_q1(double x);

76

77

78

79

80

81

82

83

84

87{

89 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

90 errmsg("value out of range: overflow")));

91}

92

95{

97 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

98 errmsg("value out of range: underflow")));

99}

100

103{

105 (errcode(ERRCODE_DIVISION_BY_ZERO),

106 errmsg("division by zero")));

107}

108

109

110

111

112

113

114

115

116

117int

119{

120 int inf = isinf(val);

121

122 if (inf == 0)

123 return 0;

124 else if (val > 0)

125 return 1;

126 else

127 return -1;

128}

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

165{

167

169 fcinfo->context));

170}

171

172

173

174

175

176

177

178

179

180

181

184 const char *type_name, const char *orig_string,

185 struct Node *escontext)

186{

187 float val;

188 char *endptr;

189

190

191

192

193

194

195

196

197 while (*num != '\0' && isspace((unsigned char) *num))

198 num++;

199

200

201

202

203

204 if (*num == '\0')

206 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

207 errmsg("invalid input syntax for type %s: \"%s\"",

208 type_name, orig_string)));

209

210 errno = 0;

211 val = strtof(num, &endptr);

212

213

214 if (endptr == num || errno != 0)

215 {

216 int save_errno = errno;

217

218

219

220

221

222

223

224

225

226

227

229 {

231 endptr = num + 3;

232 }

234 {

236 endptr = num + 8;

237 }

239 {

241 endptr = num + 9;

242 }

244 {

246 endptr = num + 9;

247 }

249 {

251 endptr = num + 3;

252 }

254 {

256 endptr = num + 4;

257 }

259 {

261 endptr = num + 4;

262 }

263 else if (save_errno == ERANGE)

264 {

265

266

267

268

269

270

271

272 if (val == 0.0 ||

273#if !defined(HUGE_VALF)

274 isinf(val)

275#else

276 (val >= HUGE_VALF || val <= -HUGE_VALF)

277#endif

278 )

279 {

280

281 char *errnumber = pstrdup(num);

282

283 errnumber[endptr - num] = '\0';

284

286 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

287 errmsg("\"%s\" is out of range for type real",

288 errnumber)));

289 }

290 }

291 else

293 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

294 errmsg("invalid input syntax for type %s: \"%s\"",

295 type_name, orig_string)));

296 }

297

298

299 while (*endptr != '\0' && isspace((unsigned char) *endptr))

300 endptr++;

301

302

303 if (endptr_p)

304 *endptr_p = endptr;

305 else if (*endptr != '\0')

307 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

308 errmsg("invalid input syntax for type %s: \"%s\"",

309 type_name, orig_string)));

310

311 return val;

312}

313

314

315

316

317

320{

324

326 {

329 }

330

333}

334

335

336

337

340{

342

344}

345

346

347

348

351{

354

358}

359

360

361

362

365{

367

369 fcinfo->context));

370}

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

396 const char *type_name, const char *orig_string,

397 struct Node *escontext)

398{

399 double val;

400 char *endptr;

401

402

403 while (*num != '\0' && isspace((unsigned char) *num))

404 num++;

405

406

407

408

409

410 if (*num == '\0')

412 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

413 errmsg("invalid input syntax for type %s: \"%s\"",

414 type_name, orig_string)));

415

416 errno = 0;

417 val = strtod(num, &endptr);

418

419

420 if (endptr == num || errno != 0)

421 {

422 int save_errno = errno;

423

424

425

426

427

428

429

430

431

432

433

435 {

437 endptr = num + 3;

438 }

440 {

442 endptr = num + 8;

443 }

445 {

447 endptr = num + 9;

448 }

450 {

452 endptr = num + 9;

453 }

455 {

457 endptr = num + 3;

458 }

460 {

462 endptr = num + 4;

463 }

465 {

467 endptr = num + 4;

468 }

469 else if (save_errno == ERANGE)

470 {

471

472

473

474

475

476

477

478

479

480

481

482 if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)

483 {

484 char *errnumber = pstrdup(num);

485

486 errnumber[endptr - num] = '\0';

488 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

489 errmsg("\"%s\" is out of range for type double precision",

490 errnumber)));

491 }

492 }

493 else

495 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

496 errmsg("invalid input syntax for type %s: \"%s\"",

497 type_name, orig_string)));

498 }

499

500

501 while (*endptr != '\0' && isspace((unsigned char) *endptr))

502 endptr++;

503

504

505 if (endptr_p)

506 *endptr_p = endptr;

507 else if (*endptr != '\0')

509 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

510 errmsg("invalid input syntax for type %s: \"%s\"",

511 type_name, orig_string)));

512

513 return val;

514}

515

516

517

518

519

520

523{

525

527}

528

529

530

531

532

533

534

535

536char *

538{

541

543 {

546 }

547

550}

551

552

553

554

557{

559

561}

562

563

564

565

568{

571

575}

576

577

578

579

580

581

582

583

584

585

586

587

588

589

592{

594

596}

597

598

599

600

603{

606

607 result = -arg1;

609}

610

613{

615

617}

618

621{

625

627 result = arg1;

628 else

629 result = arg2;

631}

632

635{

639

641 result = arg1;

642 else

643 result = arg2;

645}

646

647

648

649

650

651

652

653

654

655

658{

660

662}

663

664

665

666

667

670{

673

674 result = -arg1;

676}

677

680{

682

684}

685

688{

692

694 result = arg1;

695 else

696 result = arg2;

698}

699

702{

706

708 result = arg1;

709 else

710 result = arg2;

712}

713

714

715

716

717

718

719

720

721

722

723

724

725

726

729{

732

734}

735

738{

741

743}

744

747{

750

752}

753

756{

759

761}

762

763

764

765

766

767

768

771{

774

776}

777

780{

783

785}

786

789{

792

794}

795

798{

801

803}

804

805

806

807

808

809

810

811

812

813

814

815int

817{

819 return 1;

821 return -1;

822 return 0;

823}

824

827{

830

832}

833

836{

839

841}

842

845{

848

850}

851

854{

857

859}

860

863{

866

868}

869

872{

875

877}

878

881{

884

886}

887

888static int

890{

893

895}

896

899{

901

904}

905

906

907

908

909int

911{

913 return 1;

915 return -1;

916 return 0;

917}

918

921{

924

926}

927

930{

933

935}

936

939{

942

944}

945

948{

951

953}

954

957{

960

962}

963

966{

969

971}

972

975{

978

980}

981

982static int

984{

987

989}

990

993{

995

998}

999

1002{

1005

1006

1008}

1009

1012{

1015

1016

1018}

1019

1020

1021

1022

1023

1024

1025

1028{

1035

1036

1037

1038

1039

1040 if (isnan(offset) || offset < 0)

1042 (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),

1043 errmsg("invalid preceding or following size in window function")));

1044

1045

1046

1047

1048

1049

1050 if (isnan(val))

1051 {

1052 if (isnan(base))

1054 else

1056 }

1057 else if (isnan(base))

1058 {

1060 }

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075 if (isinf(offset) && isinf(base) &&

1076 (sub ? base > 0 : base < 0))

1078

1079

1080

1081

1082

1083

1084

1085 if (sub)

1086 sum = base - offset;

1087 else

1088 sum = base + offset;

1089

1090 if (less)

1092 else

1094}

1095

1096

1097

1098

1099

1100

1101

1104{

1111

1112

1113

1114

1115

1116 if (isnan(offset) || offset < 0)

1118 (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),

1119 errmsg("invalid preceding or following size in window function")));

1120

1121

1122

1123

1124

1125

1126 if (isnan(val))

1127 {

1128 if (isnan(base))

1130 else

1132 }

1133 else if (isnan(base))

1134 {

1136 }

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151 if (isinf(offset) && isinf(base) &&

1152 (sub ? base > 0 : base < 0))

1154

1155

1156

1157

1158

1159

1160

1161 if (sub)

1162 sum = base - offset;

1163 else

1164 sum = base + offset;

1165

1166 if (less)

1168 else

1170}

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1184{

1186

1188}

1189

1190

1191

1192

1193

1196{

1199

1200 result = (float4) num;

1201 if (unlikely(isinf(result)) && !isinf(num))

1203 if (unlikely(result == 0.0f) && num != 0.0)

1205

1207}

1208

1209

1210

1211

1212

1215{

1217

1218

1219

1220

1221

1222

1223 num = rint(num);

1224

1225

1228 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1229 errmsg("integer out of range")));

1230

1232}

1233

1234

1235

1236

1237

1240{

1242

1243

1244

1245

1246

1247

1248 num = rint(num);

1249

1250

1253 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1254 errmsg("smallint out of range")));

1255

1257}

1258

1259

1260

1261

1262

1265{

1267

1269}

1270

1271

1272

1273

1274

1277{

1279

1281}

1282

1283

1284

1285

1286

1289{

1291

1292

1293

1294

1295

1296

1297 num = rint(num);

1298

1299

1302 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1303 errmsg("integer out of range")));

1304

1306}

1307

1308

1309

1310

1311

1314{

1316

1317

1318

1319

1320

1321

1322 num = rint(num);

1323

1324

1327 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1328 errmsg("smallint out of range")));

1329

1331}

1332

1333

1334

1335

1336

1339{

1341

1343}

1344

1345

1346

1347

1348

1351{

1353

1355}

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1369{

1371

1373}

1374

1375

1376

1377

1378

1381{

1383

1385}

1386

1387

1388

1389

1390

1393{

1395

1397}

1398

1399

1400

1401

1402

1403

1406{

1409

1410 if (arg1 > 0)

1411 result = 1.0;

1412 else if (arg1 < 0)

1413 result = -1.0;

1414 else

1415 result = 0.0;

1416

1418}

1419

1420

1421

1422

1423

1424

1425

1426

1429{

1432

1433 if (arg1 >= 0)

1434 result = floor(arg1);

1435 else

1436 result = -floor(-arg1);

1437

1439}

1440

1441

1442

1443

1444

1447{

1450

1451 if (arg1 < 0)

1453 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),

1454 errmsg("cannot take square root of a negative number")));

1455

1456 result = sqrt(arg1);

1457 if (unlikely(isinf(result)) && !isinf(arg1))

1459 if (unlikely(result == 0.0) && arg1 != 0.0)

1461

1463}

1464

1465

1466

1467

1468

1471{

1474

1475 result = cbrt(arg1);

1476 if (unlikely(isinf(result)) && !isinf(arg1))

1478 if (unlikely(result == 0.0) && arg1 != 0.0)

1480

1482}

1483

1484

1485

1486

1487

1490{

1494

1495

1496

1497

1498

1499

1500

1501 if (isnan(arg1))

1502 {

1503 if (isnan(arg2) || arg2 != 0.0)

1506 }

1507 if (isnan(arg2))

1508 {

1509 if (arg1 != 1.0)

1512 }

1513

1514

1515

1516

1517

1518

1519 if (arg1 == 0 && arg2 < 0)

1521 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),

1522 errmsg("zero raised to a negative power is undefined")));

1523 if (arg1 < 0 && floor(arg2) != arg2)

1525 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),

1526 errmsg("a negative number raised to a non-integer power yields a complex result")));

1527

1528

1529

1530

1531

1532

1533 if (isinf(arg2))

1534 {

1535 float8 absx = fabs(arg1);

1536

1537 if (absx == 1.0)

1538 result = 1.0;

1539 else if (arg2 > 0.0)

1540 {

1541 if (absx > 1.0)

1542 result = arg2;

1543 else

1544 result = 0.0;

1545 }

1546 else

1547 {

1548 if (absx > 1.0)

1549 result = 0.0;

1550 else

1551 result = -arg2;

1552 }

1553 }

1554 else if (isinf(arg1))

1555 {

1556 if (arg2 == 0.0)

1557 result = 1.0;

1558 else if (arg1 > 0.0)

1559 {

1560 if (arg2 > 0.0)

1561 result = arg1;

1562 else

1563 result = 0.0;

1564 }

1565 else

1566 {

1567

1568

1569

1570

1571

1572

1573 float8 halfy = arg2 / 2;

1574 bool yisoddinteger = (floor(halfy) != halfy);

1575

1576 if (arg2 > 0.0)

1577 result = yisoddinteger ? arg1 : -arg1;

1578 else

1579 result = yisoddinteger ? -0.0 : 0.0;

1580 }

1581 }

1582 else

1583 {

1584

1585

1586

1587

1588

1589

1590

1591 errno = 0;

1592 result = pow(arg1, arg2);

1593 if (errno == EDOM || isnan(result))

1594 {

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606 if (arg1 == 0.0)

1607 result = 0.0;

1608 else

1609 {

1610 float8 absx = fabs(arg1);

1611

1612 if (absx == 1.0)

1613 result = 1.0;

1614 else if (arg2 >= 0.0 ? (absx > 1.0) : (absx < 1.0))

1616 else

1618 }

1619 }

1620 else if (errno == ERANGE)

1621 {

1622 if (result != 0.0)

1624 else

1626 }

1627 else

1628 {

1629 if (unlikely(isinf(result)))

1631 if (unlikely(result == 0.0) && arg1 != 0.0)

1633 }

1634 }

1635

1637}

1638

1639

1640

1641

1642

1645{

1648

1649

1650

1651

1652

1653

1654 if (isnan(arg1))

1655 result = arg1;

1656 else if (isinf(arg1))

1657 {

1658

1659 result = (arg1 > 0.0) ? arg1 : 0;

1660 }

1661 else

1662 {

1663

1664

1665

1666

1667 errno = 0;

1668 result = exp(arg1);

1669 if (unlikely(errno == ERANGE))

1670 {

1671 if (result != 0.0)

1673 else

1675 }

1676 else if (unlikely(isinf(result)))

1678 else if (unlikely(result == 0.0))

1680 }

1681

1683}

1684

1685

1686

1687

1688

1691{

1694

1695

1696

1697

1698

1699 if (arg1 == 0.0)

1701 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),

1702 errmsg("cannot take logarithm of zero")));

1703 if (arg1 < 0)

1705 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),

1706 errmsg("cannot take logarithm of a negative number")));

1707

1708 result = log(arg1);

1709 if (unlikely(isinf(result)) && !isinf(arg1))

1711 if (unlikely(result == 0.0) && arg1 != 1.0)

1713

1715}

1716

1717

1718

1719

1720

1723{

1726

1727

1728

1729

1730

1731

1732 if (arg1 == 0.0)

1734 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),

1735 errmsg("cannot take logarithm of zero")));

1736 if (arg1 < 0)

1738 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),

1739 errmsg("cannot take logarithm of a negative number")));

1740

1741 result = log10(arg1);

1742 if (unlikely(isinf(result)) && !isinf(arg1))

1744 if (unlikely(result == 0.0) && arg1 != 1.0)

1746

1748}

1749

1750

1751

1752

1753

1756{

1759

1760

1761 if (isnan(arg1))

1763

1764

1765

1766

1767

1768

1769 if (arg1 < -1.0 || arg1 > 1.0)

1771 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1772 errmsg("input is out of range")));

1773

1774 result = acos(arg1);

1775 if (unlikely(isinf(result)))

1777

1779}

1780

1781

1782

1783

1784

1787{

1790

1791

1792 if (isnan(arg1))

1794

1795

1796

1797

1798

1799

1800 if (arg1 < -1.0 || arg1 > 1.0)

1802 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1803 errmsg("input is out of range")));

1804

1805 result = asin(arg1);

1806 if (unlikely(isinf(result)))

1808

1810}

1811

1812

1813

1814

1815

1818{

1821

1822

1823 if (isnan(arg1))

1825

1826

1827

1828

1829

1830

1831 result = atan(arg1);

1832 if (unlikely(isinf(result)))

1834

1836}

1837

1838

1839

1840

1841

1844{

1848

1849

1850 if (isnan(arg1) || isnan(arg2))

1852

1853

1854

1855

1856

1857 result = atan2(arg1, arg2);

1858 if (unlikely(isinf(result)))

1860

1862}

1863

1864

1865

1866

1867

1870{

1873

1874

1875 if (isnan(arg1))

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893 errno = 0;

1894 result = cos(arg1);

1895 if (errno != 0 || isinf(arg1))

1897 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1898 errmsg("input is out of range")));

1899 if (unlikely(isinf(result)))

1901

1903}

1904

1905

1906

1907

1908

1911{

1914

1915

1916 if (isnan(arg1))

1918

1919

1920 errno = 0;

1921 result = tan(arg1);

1922 if (errno != 0 || isinf(arg1))

1924 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1925 errmsg("input is out of range")));

1926

1927 result = 1.0 / result;

1928

1929

1931}

1932

1933

1934

1935

1936

1939{

1942

1943

1944 if (isnan(arg1))

1946

1947

1948 errno = 0;

1949 result = sin(arg1);

1950 if (errno != 0 || isinf(arg1))

1952 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1953 errmsg("input is out of range")));

1954 if (unlikely(isinf(result)))

1956

1958}

1959

1960

1961

1962

1963

1966{

1969

1970

1971 if (isnan(arg1))

1973

1974

1975 errno = 0;

1976 result = tan(arg1);

1977 if (errno != 0 || isinf(arg1))

1979 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

1980 errmsg("input is out of range")));

1981

1982

1984}

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018static void

2020{

2029}

2030

2031#define INIT_DEGREE_CONSTANTS() \

2032do { \

2033 if (!degree_consts_set) \

2034 init_degree_constants(); \

2035} while(0)

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047static double

2049{

2050

2051

2052

2053

2054

2055

2056 if (x <= 0.5)

2057 {

2058 volatile float8 asin_x = asin(x);

2059

2060 return (asin_x / asin_0_5) * 30.0;

2061 }

2062 else

2063 {

2064 volatile float8 acos_x = acos(x);

2065

2066 return 90.0 - (acos_x / acos_0_5) * 60.0;

2067 }

2068}

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080static double

2082{

2083

2084

2085

2086

2087

2088

2089 if (x <= 0.5)

2090 {

2091 volatile float8 asin_x = asin(x);

2092

2093 return 90.0 - (asin_x / asin_0_5) * 30.0;

2094 }

2095 else

2096 {

2097 volatile float8 acos_x = acos(x);

2098

2099 return (acos_x / acos_0_5) * 60.0;

2100 }

2101}

2102

2103

2104

2105

2106

2109{

2112

2113

2114 if (isnan(arg1))

2116

2118

2119

2120

2121

2122

2123

2124 if (arg1 < -1.0 || arg1 > 1.0)

2126 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2127 errmsg("input is out of range")));

2128

2129 if (arg1 >= 0.0)

2131 else

2132 result = 90.0 + asind_q1(-arg1);

2133

2134 if (unlikely(isinf(result)))

2136

2138}

2139

2140

2141

2142

2143

2146{

2149

2150

2151 if (isnan(arg1))

2153

2155

2156

2157

2158

2159

2160

2161 if (arg1 < -1.0 || arg1 > 1.0)

2163 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2164 errmsg("input is out of range")));

2165

2166 if (arg1 >= 0.0)

2168 else

2170

2171 if (unlikely(isinf(result)))

2173

2175}

2176

2177

2178

2179

2180

2183{

2186 volatile float8 atan_arg1;

2187

2188

2189 if (isnan(arg1))

2191

2193

2194

2195

2196

2197

2198

2199

2200 atan_arg1 = atan(arg1);

2201 result = (atan_arg1 / atan_1_0) * 45.0;

2202

2203 if (unlikely(isinf(result)))

2205

2207}

2208

2209

2210

2211

2212

2215{

2219 volatile float8 atan2_arg1_arg2;

2220

2221

2222 if (isnan(arg1) || isnan(arg2))

2224

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236 atan2_arg1_arg2 = atan2(arg1, arg2);

2237 result = (atan2_arg1_arg2 / atan_1_0) * 45.0;

2238

2239 if (unlikely(isinf(result)))

2241

2243}

2244

2245

2246

2247

2248

2249

2250

2251static double

2253{

2255

2256 return (sin_x / sin_30) / 2.0;

2257}

2258

2259

2260

2261

2262

2263

2264

2265static double

2267{

2269

2271}

2272

2273

2274

2275

2276

2277

2278static double

2280{

2281

2282

2283

2284

2285

2286

2287 if (x <= 30.0)

2289 else

2291}

2292

2293

2294

2295

2296

2297

2298static double

2300{

2301

2302

2303

2304

2305

2306

2307 if (x <= 60.0)

2309 else

2311}

2312

2313

2314

2315

2316

2319{

2322 int sign = 1;

2323

2324

2325

2326

2327

2328 if (isnan(arg1))

2330

2331 if (isinf(arg1))

2333 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2334 errmsg("input is out of range")));

2335

2337

2338

2339 arg1 = fmod(arg1, 360.0);

2340

2341 if (arg1 < 0.0)

2342 {

2343

2344 arg1 = -arg1;

2345 }

2346

2347 if (arg1 > 180.0)

2348 {

2349

2350 arg1 = 360.0 - arg1;

2351 }

2352

2353 if (arg1 > 90.0)

2354 {

2355

2356 arg1 = 180.0 - arg1;

2358 }

2359

2361

2362 if (unlikely(isinf(result)))

2364

2366}

2367

2368

2369

2370

2371

2374{

2377 volatile float8 cot_arg1;

2378 int sign = 1;

2379

2380

2381

2382

2383

2384 if (isnan(arg1))

2386

2387 if (isinf(arg1))

2389 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2390 errmsg("input is out of range")));

2391

2393

2394

2395 arg1 = fmod(arg1, 360.0);

2396

2397 if (arg1 < 0.0)

2398 {

2399

2400 arg1 = -arg1;

2402 }

2403

2404 if (arg1 > 180.0)

2405 {

2406

2407 arg1 = 360.0 - arg1;

2409 }

2410

2411 if (arg1 > 90.0)

2412 {

2413

2414 arg1 = 180.0 - arg1;

2416 }

2417

2419 result = sign * (cot_arg1 / cot_45);

2420

2421

2422

2423

2424

2425

2426 if (result == 0.0)

2427 result = 0.0;

2428

2429

2430

2432}

2433

2434

2435

2436

2437

2440{

2443 int sign = 1;

2444

2445

2446

2447

2448

2449 if (isnan(arg1))

2451

2452 if (isinf(arg1))

2454 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2455 errmsg("input is out of range")));

2456

2458

2459

2460 arg1 = fmod(arg1, 360.0);

2461

2462 if (arg1 < 0.0)

2463 {

2464

2465 arg1 = -arg1;

2467 }

2468

2469 if (arg1 > 180.0)

2470 {

2471

2472 arg1 = 360.0 - arg1;

2474 }

2475

2476 if (arg1 > 90.0)

2477 {

2478

2479 arg1 = 180.0 - arg1;

2480 }

2481

2483

2484 if (unlikely(isinf(result)))

2486

2488}

2489

2490

2491

2492

2493

2496{

2499 volatile float8 tan_arg1;

2500 int sign = 1;

2501

2502

2503

2504

2505

2506 if (isnan(arg1))

2508

2509 if (isinf(arg1))

2511 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2512 errmsg("input is out of range")));

2513

2515

2516

2517 arg1 = fmod(arg1, 360.0);

2518

2519 if (arg1 < 0.0)

2520 {

2521

2522 arg1 = -arg1;

2524 }

2525

2526 if (arg1 > 180.0)

2527 {

2528

2529 arg1 = 360.0 - arg1;

2531 }

2532

2533 if (arg1 > 90.0)

2534 {

2535

2536 arg1 = 180.0 - arg1;

2538 }

2539

2541 result = sign * (tan_arg1 / tan_45);

2542

2543

2544

2545

2546

2547

2548 if (result == 0.0)

2549 result = 0.0;

2550

2551

2552

2554}

2555

2556

2557

2558

2559

2562{

2564

2566}

2567

2568

2569

2570

2571

2574{

2576}

2577

2578

2579

2580

2581

2584{

2586

2588}

2589

2590

2591

2592

2593

2594

2595

2596

2599{

2602

2603 errno = 0;

2604 result = sinh(arg1);

2605

2606

2607

2608

2609

2610

2611 if (errno == ERANGE)

2612 {

2613 if (arg1 < 0)

2615 else

2617 }

2618

2620}

2621

2622

2623

2624

2625

2628{

2631

2632 errno = 0;

2633 result = cosh(arg1);

2634

2635

2636

2637

2638

2639 if (errno == ERANGE)

2641

2642 if (unlikely(result == 0.0))

2644

2646}

2647

2648

2649

2650

2653{

2656

2657

2658

2659

2660 result = tanh(arg1);

2661

2662 if (unlikely(isinf(result)))

2664

2666}

2667

2668

2669

2670

2673{

2676

2677

2678

2679

2680 result = asinh(arg1);

2681

2683}

2684

2685

2686

2687

2690{

2693

2694

2695

2696

2697

2698

2699

2700 if (arg1 < 1.0)

2702 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2703 errmsg("input is out of range")));

2704

2705 result = acosh(arg1);

2706

2708}

2709

2710

2711

2712

2715{

2718

2719

2720

2721

2722

2723

2724 if (arg1 < -1.0 || arg1 > 1.0)

2726 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

2727 errmsg("input is out of range")));

2728

2729

2730

2731

2732

2733

2734 if (arg1 == -1.0)

2736 else if (arg1 == 1.0)

2738 else

2739 result = atanh(arg1);

2740

2742}

2743

2744

2745

2746

2747

2748

2749

2750

2753{

2756

2757

2758

2759

2760 result = erf(arg1);

2761

2762 if (unlikely(isinf(result)))

2764

2766}

2767

2768

2769

2770

2773{

2776

2777

2778

2779

2780 result = erfc(arg1);

2781

2782 if (unlikely(isinf(result)))

2784

2786}

2787

2788

2789

2790

2791

2792

2793

2794

2797{

2800

2801

2802

2803

2804

2805 if (isnan(arg1))

2806 result = arg1;

2807 else if (isinf(arg1))

2808 {

2809

2810 if (arg1 < 0)

2811 {

2813 result = get_float8_nan();

2814 }

2815 else

2816 result = arg1;

2817 }

2818 else

2819 {

2820

2821

2822

2823

2824

2825

2826

2827

2828 errno = 0;

2829 result = tgamma(arg1);

2830

2831 if (errno != 0 || isinf(result) || isnan(result))

2832 {

2833 if (result != 0.0)

2835 else

2837 }

2838 else if (result == 0.0)

2840 }

2841

2843}

2844

2845

2846

2847

2848

2851{

2854

2855

2856

2857

2858

2859

2860 errno = 0;

2861 result = lgamma(arg1);

2862

2863

2864

2865

2866

2867

2868

2869

2870 if (errno == ERANGE || (isinf(result) && !isinf(arg1)))

2872

2874}

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2928{

2929

2930

2931

2932

2933

2934 if (ARR_NDIM(transarray) != 1 ||

2935 ARR_DIMS(transarray)[0] != n ||

2938 elog(ERROR, "%s: expected %d-element float8 array", caller, n);

2940}

2941

2942

2943

2944

2945

2946

2947

2948

2949

2952{

2955 float8 *transvalues1;

2956 float8 *transvalues2;

2958 Sx1,

2959 Sxx1,

2960 N2,

2961 Sx2,

2962 Sxx2,

2963 tmp,

2964 N,

2965 Sx,

2966 Sxx;

2967

2968 transvalues1 = check_float8_array(transarray1, "float8_combine", 3);

2969 transvalues2 = check_float8_array(transarray2, "float8_combine", 3);

2970

2971 N1 = transvalues1[0];

2972 Sx1 = transvalues1[1];

2973 Sxx1 = transvalues1[2];

2974

2975 N2 = transvalues2[0];

2976 Sx2 = transvalues2[1];

2977 Sxx2 = transvalues2[2];

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992 if (N1 == 0.0)

2993 {

2994 N = N2;

2995 Sx = Sx2;

2996 Sxx = Sxx2;

2997 }

2998 else if (N2 == 0.0)

2999 {

3000 N = N1;

3001 Sx = Sx1;

3002 Sxx = Sxx1;

3003 }

3004 else

3005 {

3006 N = N1 + N2;

3008 tmp = Sx1 / N1 - Sx2 / N2;

3009 Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp * tmp / N;

3010 if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))

3012 }

3013

3014

3015

3016

3017

3018

3020 {

3021 transvalues1[0] = N;

3022 transvalues1[1] = Sx;

3023 transvalues1[2] = Sxx;

3024

3026 }

3027 else

3028 {

3029 Datum transdatums[3];

3031

3035

3037

3039 }

3040}

3041

3044{

3047 float8 *transvalues;

3049 Sx,

3050 Sxx,

3051 tmp;

3052

3054 N = transvalues[0];

3055 Sx = transvalues[1];

3056 Sxx = transvalues[2];

3057

3058

3059

3060

3061

3062 N += 1.0;

3064 if (transvalues[0] > 0.0)

3065 {

3066 tmp = newval * N - Sx;

3067 Sxx += tmp * tmp / (N * transvalues[0]);

3068

3069

3070

3071

3072

3073

3074

3075 if (isinf(Sx) || isinf(Sxx))

3076 {

3077 if (!isinf(transvalues[1]) && !isinf(newval))

3079

3081 }

3082 }

3083 else

3084 {

3085

3086

3087

3088

3089

3090

3093 }

3094

3095

3096

3097

3098

3099

3101 {

3102 transvalues[0] = N;

3103 transvalues[1] = Sx;

3104 transvalues[2] = Sxx;

3105

3107 }

3108 else

3109 {

3110 Datum transdatums[3];

3112

3116

3118

3120 }

3121}

3122

3125{

3127

3128

3130 float8 *transvalues;

3132 Sx,

3133 Sxx,

3134 tmp;

3135

3137 N = transvalues[0];

3138 Sx = transvalues[1];

3139 Sxx = transvalues[2];

3140

3141

3142

3143

3144

3145 N += 1.0;

3147 if (transvalues[0] > 0.0)

3148 {

3149 tmp = newval * N - Sx;

3150 Sxx += tmp * tmp / (N * transvalues[0]);

3151

3152

3153

3154

3155

3156

3157

3158 if (isinf(Sx) || isinf(Sxx))

3159 {

3160 if (!isinf(transvalues[1]) && !isinf(newval))

3162

3164 }

3165 }

3166 else

3167 {

3168

3169

3170

3171

3172

3173

3176 }

3177

3178

3179

3180

3181

3182

3184 {

3185 transvalues[0] = N;

3186 transvalues[1] = Sx;

3187 transvalues[2] = Sxx;

3188

3190 }

3191 else

3192 {

3193 Datum transdatums[3];

3195

3199

3201

3203 }

3204}

3205

3208{

3210 float8 *transvalues;

3212 Sx;

3213

3215 N = transvalues[0];

3216 Sx = transvalues[1];

3217

3218

3219

3220 if (N == 0.0)

3222

3224}

3225

3228{

3230 float8 *transvalues;

3232 Sxx;

3233

3235 N = transvalues[0];

3236

3237 Sxx = transvalues[2];

3238

3239

3240 if (N == 0.0)

3242

3243

3244

3246}

3247

3250{

3252 float8 *transvalues;

3254 Sxx;

3255

3257 N = transvalues[0];

3258

3259 Sxx = transvalues[2];

3260

3261

3262 if (N <= 1.0)

3264

3265

3266

3268}

3269

3272{

3274 float8 *transvalues;

3276 Sxx;

3277

3278 transvalues = check_float8_array(transarray, "float8_stddev_pop", 3);

3279 N = transvalues[0];

3280

3281 Sxx = transvalues[2];

3282

3283

3284 if (N == 0.0)

3286

3287

3288

3290}

3291

3294{

3296 float8 *transvalues;

3298 Sxx;

3299

3300 transvalues = check_float8_array(transarray, "float8_stddev_samp", 3);

3301 N = transvalues[0];

3302

3303 Sxx = transvalues[2];

3304

3305

3306 if (N <= 1.0)

3308

3309

3310

3312}

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3337{

3341 float8 *transvalues;

3343 Sx,

3344 Sxx,

3345 Sy,

3346 Syy,

3347 Sxy,

3348 tmpX,

3349 tmpY,

3351

3352 transvalues = check_float8_array(transarray, "float8_regr_accum", 6);

3353 N = transvalues[0];

3354 Sx = transvalues[1];

3355 Sxx = transvalues[2];

3356 Sy = transvalues[3];

3357 Syy = transvalues[4];

3358 Sxy = transvalues[5];

3359

3360

3361

3362

3363

3364 N += 1.0;

3365 Sx += newvalX;

3366 Sy += newvalY;

3367 if (transvalues[0] > 0.0)

3368 {

3369 tmpX = newvalX * N - Sx;

3370 tmpY = newvalY * N - Sy;

3371 scale = 1.0 / (N * transvalues[0]);

3372 Sxx += tmpX * tmpX * scale;

3373 Syy += tmpY * tmpY * scale;

3374 Sxy += tmpX * tmpY * scale;

3375

3376

3377

3378

3379

3380

3381

3382 if (isinf(Sx) || isinf(Sxx) || isinf(Sy) || isinf(Syy) || isinf(Sxy))

3383 {

3384 if (((isinf(Sx) || isinf(Sxx)) &&

3385 !isinf(transvalues[1]) && !isinf(newvalX)) ||

3386 ((isinf(Sy) || isinf(Syy)) &&

3387 !isinf(transvalues[3]) && !isinf(newvalY)) ||

3388 (isinf(Sxy) &&

3389 !isinf(transvalues[1]) && !isinf(newvalX) &&

3390 !isinf(transvalues[3]) && !isinf(newvalY)))

3392

3393 if (isinf(Sxx))

3395 if (isinf(Syy))

3397 if (isinf(Sxy))

3399 }

3400 }

3401 else

3402 {

3403

3404

3405

3406

3407

3408

3409 if (isnan(newvalX) || isinf(newvalX))

3411 if (isnan(newvalY) || isinf(newvalY))

3413 }

3414

3415

3416

3417

3418

3419

3421 {

3422 transvalues[0] = N;

3423 transvalues[1] = Sx;

3424 transvalues[2] = Sxx;

3425 transvalues[3] = Sy;

3426 transvalues[4] = Syy;

3427 transvalues[5] = Sxy;

3428

3430 }

3431 else

3432 {

3433 Datum transdatums[6];

3435

3442

3444

3446 }

3447}

3448

3449

3450

3451

3452

3453

3454

3455

3456

3459{

3462 float8 *transvalues1;

3463 float8 *transvalues2;

3465 Sx1,

3466 Sxx1,

3467 Sy1,

3468 Syy1,

3469 Sxy1,

3470 N2,

3471 Sx2,

3472 Sxx2,

3473 Sy2,

3474 Syy2,

3475 Sxy2,

3476 tmp1,

3477 tmp2,

3478 N,

3479 Sx,

3480 Sxx,

3481 Sy,

3482 Syy,

3483 Sxy;

3484

3485 transvalues1 = check_float8_array(transarray1, "float8_regr_combine", 6);

3486 transvalues2 = check_float8_array(transarray2, "float8_regr_combine", 6);

3487

3488 N1 = transvalues1[0];

3489 Sx1 = transvalues1[1];

3490 Sxx1 = transvalues1[2];

3491 Sy1 = transvalues1[3];

3492 Syy1 = transvalues1[4];

3493 Sxy1 = transvalues1[5];

3494

3495 N2 = transvalues2[0];

3496 Sx2 = transvalues2[1];

3497 Sxx2 = transvalues2[2];

3498 Sy2 = transvalues2[3];

3499 Syy2 = transvalues2[4];

3500 Sxy2 = transvalues2[5];

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518 if (N1 == 0.0)

3519 {

3520 N = N2;

3521 Sx = Sx2;

3522 Sxx = Sxx2;

3523 Sy = Sy2;

3524 Syy = Syy2;

3525 Sxy = Sxy2;

3526 }

3527 else if (N2 == 0.0)

3528 {

3529 N = N1;

3530 Sx = Sx1;

3531 Sxx = Sxx1;

3532 Sy = Sy1;

3533 Syy = Syy1;

3534 Sxy = Sxy1;

3535 }

3536 else

3537 {

3538 N = N1 + N2;

3540 tmp1 = Sx1 / N1 - Sx2 / N2;

3541 Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp1 * tmp1 / N;

3542 if (unlikely(isinf(Sxx)) && !isinf(Sxx1) && !isinf(Sxx2))

3545 tmp2 = Sy1 / N1 - Sy2 / N2;

3546 Syy = Syy1 + Syy2 + N1 * N2 * tmp2 * tmp2 / N;

3547 if (unlikely(isinf(Syy)) && !isinf(Syy1) && !isinf(Syy2))

3549 Sxy = Sxy1 + Sxy2 + N1 * N2 * tmp1 * tmp2 / N;

3550 if (unlikely(isinf(Sxy)) && !isinf(Sxy1) && !isinf(Sxy2))

3552 }

3553

3554

3555

3556

3557

3558

3560 {

3561 transvalues1[0] = N;

3562 transvalues1[1] = Sx;

3563 transvalues1[2] = Sxx;

3564 transvalues1[3] = Sy;

3565 transvalues1[4] = Syy;

3566 transvalues1[5] = Sxy;

3567

3569 }

3570 else

3571 {

3572 Datum transdatums[6];

3574

3581

3583

3585 }

3586}

3587

3588

3591{

3593 float8 *transvalues;

3595 Sxx;

3596

3598 N = transvalues[0];

3599 Sxx = transvalues[2];

3600

3601

3602 if (N < 1.0)

3604

3605

3606

3608}

3609

3612{

3614 float8 *transvalues;

3616 Syy;

3617

3619 N = transvalues[0];

3620 Syy = transvalues[4];

3621

3622

3623 if (N < 1.0)

3625

3626

3627

3629}

3630

3633{

3635 float8 *transvalues;

3637 Sxy;

3638

3640 N = transvalues[0];

3641 Sxy = transvalues[5];

3642

3643

3644 if (N < 1.0)

3646

3647

3648

3650}

3651

3654{

3656 float8 *transvalues;

3658 Sx;

3659

3660 transvalues = check_float8_array(transarray, "float8_regr_avgx", 6);

3661 N = transvalues[0];

3662 Sx = transvalues[1];

3663

3664

3665 if (N < 1.0)

3667

3669}

3670

3673{

3675 float8 *transvalues;

3677 Sy;

3678

3679 transvalues = check_float8_array(transarray, "float8_regr_avgy", 6);

3680 N = transvalues[0];

3681 Sy = transvalues[3];

3682

3683

3684 if (N < 1.0)

3686

3688}

3689

3692{

3694 float8 *transvalues;

3696 Sxy;

3697

3698 transvalues = check_float8_array(transarray, "float8_covar_pop", 6);

3699 N = transvalues[0];

3700 Sxy = transvalues[5];

3701

3702

3703 if (N < 1.0)

3705

3707}

3708

3711{

3713 float8 *transvalues;

3715 Sxy;

3716

3717 transvalues = check_float8_array(transarray, "float8_covar_samp", 6);

3718 N = transvalues[0];

3719 Sxy = transvalues[5];

3720

3721

3722 if (N < 2.0)

3724

3726}

3727

3730{

3732 float8 *transvalues;

3734 Sxx,

3735 Syy,

3736 Sxy;

3737

3739 N = transvalues[0];

3740 Sxx = transvalues[2];

3741 Syy = transvalues[4];

3742 Sxy = transvalues[5];

3743

3744

3745 if (N < 1.0)

3747

3748

3749

3750

3751 if (Sxx == 0 || Syy == 0)

3753

3755}

3756

3759{

3761 float8 *transvalues;

3763 Sxx,

3764 Syy,

3765 Sxy;

3766

3768 N = transvalues[0];

3769 Sxx = transvalues[2];

3770 Syy = transvalues[4];

3771 Sxy = transvalues[5];

3772

3773

3774 if (N < 1.0)

3776

3777

3778

3779

3780 if (Sxx == 0)

3782

3783

3784 if (Syy == 0)

3786

3788}

3789

3792{

3794 float8 *transvalues;

3796 Sxx,

3797 Sxy;

3798

3799 transvalues = check_float8_array(transarray, "float8_regr_slope", 6);

3800 N = transvalues[0];

3801 Sxx = transvalues[2];

3802 Sxy = transvalues[5];

3803

3804

3805 if (N < 1.0)

3807

3808

3809

3810

3811 if (Sxx == 0)

3813

3815}

3816

3819{

3821 float8 *transvalues;

3823 Sx,

3824 Sxx,

3825 Sy,

3826 Sxy;

3827

3828 transvalues = check_float8_array(transarray, "float8_regr_intercept", 6);

3829 N = transvalues[0];

3830 Sx = transvalues[1];

3831 Sxx = transvalues[2];

3832 Sy = transvalues[3];

3833 Sxy = transvalues[5];

3834

3835

3836 if (N < 1.0)

3838

3839

3840

3841

3842 if (Sxx == 0)

3844

3846}

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3863{

3866

3868}

3869

3872{

3875

3877}

3878

3881{

3884

3886}

3887

3890{

3893

3895}

3896

3897

3898

3899

3900

3901

3902

3905{

3908

3910}

3911

3914{

3917

3919}

3920

3923{

3926

3928}

3929

3932{

3935

3937}

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3950{

3953

3955}

3956

3959{

3962

3964}

3965

3968{

3971

3973}

3974

3977{

3980

3982}

3983

3986{

3989

3991}

3992

3995{

3998

4000}

4001

4002

4003

4004

4007{

4010

4012}

4013

4016{

4019

4021}

4022

4025{

4028

4030}

4031

4034{

4037

4039}

4040

4043{

4046

4048}

4049

4052{

4055

4057}

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4075{

4081

4082 if (count <= 0)

4084 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),

4085 errmsg("count must be greater than zero")));

4086

4087 if (isnan(operand) || isnan(bound1) || isnan(bound2))

4089 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),

4090 errmsg("operand, lower bound, and upper bound cannot be NaN")));

4091

4092

4093 if (isinf(bound1) || isinf(bound2))

4095 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),

4096 errmsg("lower and upper bounds must be finite")));

4097

4098 if (bound1 < bound2)

4099 {

4100 if (operand < bound1)

4101 result = 0;

4102 else if (operand >= bound2)

4103 {

4106 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

4107 errmsg("integer out of range")));

4108 }

4109 else

4110 {

4111 if (!isinf(bound2 - bound1))

4112 {

4113

4114 result = count * ((operand - bound1) / (bound2 - bound1));

4115 }

4116 else

4117 {

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127 result = count * ((operand / 2 - bound1 / 2) / (bound2 / 2 - bound1 / 2));

4128 }

4129

4130 if (result >= count)

4131 result = count - 1;

4132

4133 result++;

4134 }

4135 }

4136 else if (bound1 > bound2)

4137 {

4138 if (operand > bound1)

4139 result = 0;

4140 else if (operand <= bound2)

4141 {

4144 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

4145 errmsg("integer out of range")));

4146 }

4147 else

4148 {

4149 if (!isinf(bound1 - bound2))

4150 result = count * ((bound1 - operand) / (bound1 - bound2));

4151 else

4152 result = count * ((bound1 / 2 - operand / 2) / (bound1 / 2 - bound2 / 2));

4153 if (result >= count)

4154 result = count - 1;

4155 result++;

4156 }

4157 }

4158 else

4159 {

4161 (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),

4162 errmsg("lower bound cannot equal upper bound")));

4163 result = 0;

4164 }

4165

4167}

#define PG_GETARG_ARRAYTYPE_P(n)

#define PG_RETURN_ARRAYTYPE_P(x)

ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)

#define FLOAT4_FITS_IN_INT32(num)

#define FLOAT8_FITS_IN_INT32(num)

#define FLOAT4_FITS_IN_INT16(num)

#define FLOAT8_FITS_IN_INT16(num)

int double_to_shortest_decimal_buf(double f, char *result)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereturn(context, dummy_value,...)

#define ereport(elevel,...)

int float_to_shortest_decimal_buf(float f, char *result)

float8 float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)

Datum float4lt(PG_FUNCTION_ARGS)

Datum dceil(PG_FUNCTION_ARGS)

Datum btfloat4cmp(PG_FUNCTION_ARGS)

Datum float84gt(PG_FUNCTION_ARGS)

Datum dasinh(PG_FUNCTION_ARGS)

Datum float84mi(PG_FUNCTION_ARGS)

static double sind_0_to_30(double x)

Datum dtof(PG_FUNCTION_ARGS)

Datum radians(PG_FUNCTION_ARGS)

pg_noinline void float_zero_divide_error(void)

pg_noinline void float_overflow_error(void)

Datum width_bucket_float8(PG_FUNCTION_ARGS)

Datum dasind(PG_FUNCTION_ARGS)

Datum float8_var_samp(PG_FUNCTION_ARGS)

Datum btfloat84cmp(PG_FUNCTION_ARGS)

Datum ftoi4(PG_FUNCTION_ARGS)

Datum dsind(PG_FUNCTION_ARGS)

Datum datan2(PG_FUNCTION_ARGS)

Datum derfc(PG_FUNCTION_ARGS)

Datum float8div(PG_FUNCTION_ARGS)

Datum float8_regr_syy(PG_FUNCTION_ARGS)

Datum float48gt(PG_FUNCTION_ARGS)

Datum degrees(PG_FUNCTION_ARGS)

Datum btfloat4sortsupport(PG_FUNCTION_ARGS)

Datum dlgamma(PG_FUNCTION_ARGS)

Datum dacosd(PG_FUNCTION_ARGS)

static double acosd_q1(double x)

Datum float8_regr_r2(PG_FUNCTION_ARGS)

Datum float8_regr_combine(PG_FUNCTION_ARGS)

Datum float8_regr_slope(PG_FUNCTION_ARGS)

Datum float8eq(PG_FUNCTION_ARGS)

Datum dtanh(PG_FUNCTION_ARGS)

static double cosd_q1(double x)

Datum dlog10(PG_FUNCTION_ARGS)

Datum float84mul(PG_FUNCTION_ARGS)

static bool degree_consts_set

Datum datanh(PG_FUNCTION_ARGS)

Datum dcosd(PG_FUNCTION_ARGS)

static int btfloat8fastcmp(Datum x, Datum y, SortSupport ssup)

Datum derf(PG_FUNCTION_ARGS)

Datum float4up(PG_FUNCTION_ARGS)

Datum float48pl(PG_FUNCTION_ARGS)

Datum dsinh(PG_FUNCTION_ARGS)

Datum float8_combine(PG_FUNCTION_ARGS)

Datum float8_avg(PG_FUNCTION_ARGS)

Datum float8_covar_pop(PG_FUNCTION_ARGS)

Datum dtan(PG_FUNCTION_ARGS)

Datum float8ge(PG_FUNCTION_ARGS)

Datum float8_stddev_pop(PG_FUNCTION_ARGS)

static double asind_q1(double x)

Datum dround(PG_FUNCTION_ARGS)

Datum float4um(PG_FUNCTION_ARGS)

Datum dlog1(PG_FUNCTION_ARGS)

Datum datan2d(PG_FUNCTION_ARGS)

Datum float4abs(PG_FUNCTION_ARGS)

Datum ftod(PG_FUNCTION_ARGS)

Datum float4mul(PG_FUNCTION_ARGS)

Datum float4le(PG_FUNCTION_ARGS)

Datum dcos(PG_FUNCTION_ARGS)

Datum float8_regr_intercept(PG_FUNCTION_ARGS)

Datum float8out(PG_FUNCTION_ARGS)

Datum float84le(PG_FUNCTION_ARGS)

Datum dexp(PG_FUNCTION_ARGS)

Datum float8pl(PG_FUNCTION_ARGS)

Datum float8lt(PG_FUNCTION_ARGS)

Datum float4gt(PG_FUNCTION_ARGS)

Datum float4out(PG_FUNCTION_ARGS)

#define INIT_DEGREE_CONSTANTS()

Datum dsign(PG_FUNCTION_ARGS)

Datum float8recv(PG_FUNCTION_ARGS)

Datum float4send(PG_FUNCTION_ARGS)

Datum float4ne(PG_FUNCTION_ARGS)

Datum float84eq(PG_FUNCTION_ARGS)

Datum float84lt(PG_FUNCTION_ARGS)

Datum float48mi(PG_FUNCTION_ARGS)

Datum float8le(PG_FUNCTION_ARGS)

Datum dtrunc(PG_FUNCTION_ARGS)

Datum btfloat8cmp(PG_FUNCTION_ARGS)

Datum float8in(PG_FUNCTION_ARGS)

Datum float8ne(PG_FUNCTION_ARGS)

Datum dpow(PG_FUNCTION_ARGS)

Datum float8mi(PG_FUNCTION_ARGS)

static double sind_q1(double x)

Datum ftoi2(PG_FUNCTION_ARGS)

Datum float4mi(PG_FUNCTION_ARGS)

Datum float8_accum(PG_FUNCTION_ARGS)

Datum float48eq(PG_FUNCTION_ARGS)

Datum i2tof(PG_FUNCTION_ARGS)

static float8 one_minus_cos_60

Datum float84pl(PG_FUNCTION_ARGS)

Datum btfloat48cmp(PG_FUNCTION_ARGS)

Datum float48ge(PG_FUNCTION_ARGS)

Datum float84div(PG_FUNCTION_ARGS)

Datum dcotd(PG_FUNCTION_ARGS)

pg_noinline void float_underflow_error(void)

Datum float8smaller(PG_FUNCTION_ARGS)

float8 degree_c_forty_five

Datum dsqrt(PG_FUNCTION_ARGS)

Datum float84ge(PG_FUNCTION_ARGS)

Datum float8_stddev_samp(PG_FUNCTION_ARGS)

Datum datand(PG_FUNCTION_ARGS)

Datum float8larger(PG_FUNCTION_ARGS)

Datum dcbrt(PG_FUNCTION_ARGS)

Datum float4in(PG_FUNCTION_ARGS)

static int btfloat4fastcmp(Datum x, Datum y, SortSupport ssup)

Datum float8_regr_sxy(PG_FUNCTION_ARGS)

Datum float8_var_pop(PG_FUNCTION_ARGS)

Datum float48div(PG_FUNCTION_ARGS)

Datum float84ne(PG_FUNCTION_ARGS)

Datum float4_accum(PG_FUNCTION_ARGS)

Datum float8up(PG_FUNCTION_ARGS)

int float4_cmp_internal(float4 a, float4 b)

Datum float48le(PG_FUNCTION_ARGS)

Datum float8_regr_sxx(PG_FUNCTION_ARGS)

Datum float8_corr(PG_FUNCTION_ARGS)

Datum float4recv(PG_FUNCTION_ARGS)

Datum in_range_float8_float8(PG_FUNCTION_ARGS)

Datum float48ne(PG_FUNCTION_ARGS)

Datum dpi(PG_FUNCTION_ARGS)

float4 float4in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)

Datum dacos(PG_FUNCTION_ARGS)

Datum float48lt(PG_FUNCTION_ARGS)

static void init_degree_constants(void)

Datum dgamma(PG_FUNCTION_ARGS)

Datum float8mul(PG_FUNCTION_ARGS)

Datum float4div(PG_FUNCTION_ARGS)

Datum in_range_float4_float8(PG_FUNCTION_ARGS)

Datum dtand(PG_FUNCTION_ARGS)

Datum float8abs(PG_FUNCTION_ARGS)

Datum i4tod(PG_FUNCTION_ARGS)

int is_infinite(double val)

Datum i2tod(PG_FUNCTION_ARGS)

Datum dfloor(PG_FUNCTION_ARGS)

Datum btfloat8sortsupport(PG_FUNCTION_ARGS)

Datum dcosh(PG_FUNCTION_ARGS)

Datum dacosh(PG_FUNCTION_ARGS)

Datum float4ge(PG_FUNCTION_ARGS)

Datum dasin(PG_FUNCTION_ARGS)

Datum i4tof(PG_FUNCTION_ARGS)

Datum datan(PG_FUNCTION_ARGS)

Datum float8gt(PG_FUNCTION_ARGS)

Datum float8_regr_avgx(PG_FUNCTION_ARGS)

Datum float8um(PG_FUNCTION_ARGS)

Datum float8_regr_avgy(PG_FUNCTION_ARGS)

Datum dcot(PG_FUNCTION_ARGS)

Datum dsin(PG_FUNCTION_ARGS)

Datum dtoi4(PG_FUNCTION_ARGS)

Datum float4pl(PG_FUNCTION_ARGS)

Datum float8_covar_samp(PG_FUNCTION_ARGS)

Datum float8send(PG_FUNCTION_ARGS)

Datum float4larger(PG_FUNCTION_ARGS)

Datum dtoi2(PG_FUNCTION_ARGS)

static float8 * check_float8_array(ArrayType *transarray, const char *caller, int n)

static double cosd_0_to_60(double x)

Datum float48mul(PG_FUNCTION_ARGS)

Datum float4smaller(PG_FUNCTION_ARGS)

Datum float8_regr_accum(PG_FUNCTION_ARGS)

char * float8out_internal(double num)

int float8_cmp_internal(float8 a, float8 b)

Datum float4eq(PG_FUNCTION_ARGS)

static float8 float8_mul(const float8 val1, const float8 val2)

static float4 float4_div(const float4 val1, const float4 val2)

#define RADIANS_PER_DEGREE

static float4 get_float4_infinity(void)

static bool float4_lt(const float4 val1, const float4 val2)

static float8 float8_pl(const float8 val1, const float8 val2)

static float8 float8_mi(const float8 val1, const float8 val2)

static bool float4_ge(const float4 val1, const float4 val2)

static float4 get_float4_nan(void)

static bool float8_ne(const float8 val1, const float8 val2)

static bool float4_ne(const float4 val1, const float4 val2)

static float4 float4_pl(const float4 val1, const float4 val2)

static bool float4_eq(const float4 val1, const float4 val2)

static float4 float4_mul(const float4 val1, const float4 val2)

static float8 get_float8_infinity(void)

static bool float8_ge(const float8 val1, const float8 val2)

static float4 float4_mi(const float4 val1, const float4 val2)

static bool float8_le(const float8 val1, const float8 val2)

static bool float4_gt(const float4 val1, const float4 val2)

static bool float8_eq(const float8 val1, const float8 val2)

static bool float4_le(const float4 val1, const float4 val2)

static float8 get_float8_nan(void)

static float8 float8_div(const float8 val1, const float8 val2)

static bool float8_lt(const float8 val1, const float8 val2)

static bool float8_gt(const float8 val1, const float8 val2)

#define PG_RETURN_BYTEA_P(x)

#define PG_GETARG_FLOAT8(n)

#define PG_RETURN_FLOAT8(x)

#define PG_GETARG_POINTER(n)

#define PG_RETURN_CSTRING(x)

#define PG_GETARG_CSTRING(n)

#define PG_RETURN_INT16(x)

#define PG_RETURN_INT32(x)

#define PG_GETARG_INT32(n)

#define PG_GETARG_BOOL(n)

#define PG_GETARG_FLOAT4(n)

#define PG_RETURN_FLOAT4(x)

#define PG_RETURN_BOOL(x)

#define PG_GETARG_INT16(n)

static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)

char * pstrdup(const char *in)

int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)

Datum ascii(PG_FUNCTION_ARGS)

int pg_strfromd(char *str, size_t count, int precision, double value)

int pg_strncasecmp(const char *s1, const char *s2, size_t n)

static float4 DatumGetFloat4(Datum X)

#define Float8GetDatumFast(X)

static float8 DatumGetFloat8(Datum X)

float4 pq_getmsgfloat4(StringInfo msg)

float8 pq_getmsgfloat8(StringInfo msg)

void pq_begintypsend(StringInfo buf)

void pq_sendfloat4(StringInfo buf, float4 f)

bytea * pq_endtypsend(StringInfo buf)

void pq_sendfloat8(StringInfo buf, float8 f)

struct SortSupportData * SortSupport

StringInfoData * StringInfo

int(* comparator)(Datum x, Datum y, SortSupport ssup)