PostgreSQL Source Code: src/include/utils/float.h File Reference (original) (raw)

#include <math.h>

Go to the source code of this file.

Functions
pg_noreturn void float_overflow_error (void)
pg_noreturn void float_underflow_error (void)
pg_noreturn void float_zero_divide_error (void)
int is_infinite (float8 val)
float8 float8in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
float4 float4in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
char * float8out_internal (float8 num)
int float4_cmp_internal (float4 a, float4 b)
int float8_cmp_internal (float8 a, float8 b)
static float4 get_float4_infinity (void)
static float8 get_float8_infinity (void)
static float4 get_float4_nan (void)
static float8 get_float8_nan (void)
static float4 float4_pl (const float4 val1, const float4 val2)
static float8 float8_pl (const float8 val1, const float8 val2)
static float4 float4_mi (const float4 val1, const float4 val2)
static float8 float8_mi (const float8 val1, const float8 val2)
static float4 float4_mul (const float4 val1, const float4 val2)
static float8 float8_mul (const float8 val1, const float8 val2)
static float4 float4_div (const float4 val1, const float4 val2)
static float8 float8_div (const float8 val1, const float8 val2)
static bool float4_eq (const float4 val1, const float4 val2)
static bool float8_eq (const float8 val1, const float8 val2)
static bool float4_ne (const float4 val1, const float4 val2)
static bool float8_ne (const float8 val1, const float8 val2)
static bool float4_lt (const float4 val1, const float4 val2)
static bool float8_lt (const float8 val1, const float8 val2)
static bool float4_le (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_gt (const float8 val1, const float8 val2)
static bool float4_ge (const float4 val1, const float4 val2)
static bool float8_ge (const float8 val1, const float8 val2)
static float4 float4_min (const float4 val1, const float4 val2)
static float8 float8_min (const float8 val1, const float8 val2)
static float4 float4_max (const float4 val1, const float4 val2)
static float8 float8_max (const float8 val1, const float8 val2)

M_PI

#define M_PI 3.14159265358979323846

Definition at line 22 of file float.h.

RADIANS_PER_DEGREE

#define RADIANS_PER_DEGREE 0.0174532925199432957692

Definition at line 26 of file float.h.

float4_cmp_internal()

float4_div()

float4_eq()

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

Definition at line 262 of file float.h.

263{

264 return isnan(val1) ? isnan(val2) : !isnan(val2) && val1 == val2;

265}

Referenced by float4eq().

float4_ge()

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

Definition at line 322 of file float.h.

323{

324 return isnan(val1) || (!isnan(val2) && val1 >= val2);

325}

Referenced by float4ge().

float4_gt()

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

float4_le()

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

Definition at line 298 of file float.h.

299{

300 return isnan(val2) || (!isnan(val1) && val1 <= val2);

301}

Referenced by float4le().

float4_lt()

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

float4_max()

float4_mi()

float4_min()

float4_mul()

float4_ne()

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

Definition at line 274 of file float.h.

275{

276 return isnan(val1) ? !isnan(val2) : isnan(val2) || val1 != val2;

277}

Referenced by float4ne().

float4_pl()

float4in_internal()

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

Definition at line 183 of file float.c.

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}

int errcode(int sqlerrcode)

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

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

static float4 get_float4_infinity(void)

static float4 get_float4_nan(void)

char * pstrdup(const char *in)

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

References ereturn, errcode(), errmsg(), get_float4_infinity(), get_float4_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by float4in().

float8_cmp_internal()

Definition at line 910 of file float.c.

911{

913 return 1;

915 return -1;

916 return 0;

917}

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

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

References a, b, float8_gt(), and float8_lt().

Referenced by btfloat48cmp(), btfloat84cmp(), btfloat8cmp(), btfloat8fastcmp(), common_entry_cmp(), gbt_float8_ssup_cmp(), interval_cmp_lower(), interval_cmp_upper(), and pairingheap_GISTSearchItem_cmp().

float8_div()

Definition at line 238 of file float.h.

239{

241

242 if (unlikely(val2 == 0.0) && !isnan(val1))

244 result = val1 / val2;

245 if (unlikely(isinf(result)) && !isinf(val1))

247 if (unlikely(result == 0.0) && val1 != 0.0 && !isinf(val2))

249

250 return result;

251}

References float_overflow_error(), float_underflow_error(), float_zero_divide_error(), and unlikely.

Referenced by box_circle(), box_cn(), cash_div_float8(), circle_box(), circle_div_pt(), circle_poly(), degrees(), float48div(), float84div(), float8div(), g_box_consider_split(), line_distance(), line_eq(), line_interpt_line(), line_invsl(), line_perp(), line_sl(), lseg_center(), lseg_inside_poly(), path_area(), point_div_point(), point_invsl(), point_sl(), and poly_to_circle().

float8_eq()

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

float8_ge()

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

float8_gt()

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

float8_le()

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

float8_lt()

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

Definition at line 292 of file float.h.

293{

294 return !isnan(val1) && (isnan(val2) || val1 < val2);

295}

Referenced by adjustBox(), box_closept_lseg(), box_closept_point(), box_in(), box_recv(), dist_ppath_internal(), dist_ppoly_internal(), float48lt(), float84lt(), float8_cmp_internal(), float8_min(), float8lt(), float8smaller(), gist_box_picksplit(), lseg_closept_lseg(), make_bound_box(), path_distance(), and poly_distance().

float8_max()

float8_mi()

Definition at line 182 of file float.h.

183{

185

186 result = val1 - val2;

187 if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))

189

190 return result;

191}

References float_overflow_error(), and unlikely.

Referenced by box_ht(), box_penalty(), box_wd(), circle_above(), circle_below(), circle_box(), circle_contain(), circle_contained(), circle_distance(), circle_left(), circle_overabove(), circle_overright(), circle_poly(), circle_right(), computeDistance(), dist_cpoint(), dist_cpoly_internal(), dist_pc(), float48mi(), float84mi(), float8mi(), g_box_consider_split(), gist_box_picksplit(), gist_circle_compress(), gist_circle_consistent(), line_construct(), line_distance(), line_interpt_line(), lseg_crossing(), path_area(), point_div_point(), point_dt(), point_inside(), point_invsl(), point_mul_point(), point_sl(), point_sub_point(), and size_box().

float8_min()

float8_mul()

Definition at line 208 of file float.h.

209{

211

212 result = val1 * val2;

213 if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))

215 if (unlikely(result == 0.0) && val1 != 0.0 && val2 != 0.0)

217

218 return result;

219}

References float_overflow_error(), float_underflow_error(), and unlikely.

Referenced by box_ar(), cash_mul_float8(), circle_ar(), circle_diameter(), circle_mul_pt(), circle_poly(), float48mul(), float84mul(), float8mul(), line_construct(), line_contain_point(), line_distance(), line_eq(), line_interpt_line(), line_perp(), lseg_crossing(), make_interval(), path_area(), point_div_point(), point_mul_point(), radians(), and size_box().

float8_ne()

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

float8_pl()

Definition at line 158 of file float.h.

159{

161

162 result = val1 + val2;

163 if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2))

165

166 return result;

167}

References float_overflow_error(), and unlikely.

Referenced by box_circle(), box_cn(), circle_above(), circle_below(), circle_box(), circle_distance(), circle_left(), circle_overbelow(), circle_overlap(), circle_overleft(), circle_poly(), circle_right(), float48pl(), float84pl(), float8_combine(), float8_regr_combine(), float8pl(), gist_circle_compress(), gist_circle_consistent(), line_contain_point(), line_interpt_line(), lseg_center(), lseg_inside_poly(), on_ppath(), path_area(), path_length(), point_add_point(), point_div_point(), point_mul_point(), and poly_to_circle().

float8in_internal()

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

Definition at line 395 of file float.c.

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}

static float8 get_float8_infinity(void)

static float8 get_float8_nan(void)

References ereturn, errcode(), errmsg(), get_float8_infinity(), get_float8_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by executeItemOptUnwrapTarget(), float8in(), and single_decode().

float8out_internal()

char * float8out_internal ( float8 num )

Definition at line 537 of file float.c.

538{

541

543 {

546 }

547

550}

int double_to_shortest_decimal_buf(double f, char *result)

Datum ascii(PG_FUNCTION_ARGS)

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

References ascii(), double_to_shortest_decimal_buf(), extra_float_digits, palloc(), and pg_strfromd().

Referenced by cube_out(), float8out(), line_out(), pair_encode(), and single_encode().

float_overflow_error()

Definition at line 86 of file float.c.

87{

89 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

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

91}

#define ereport(elevel,...)

References ereport, errcode(), errmsg(), and ERROR.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcbrt(), dcos(), dcosd(), derf(), derfc(), dexp(), dgamma(), dlgamma(), dlog1(), dlog10(), dpow(), dsin(), dsind(), dsqrt(), dtanh(), dtof(), float4_accum(), float4_dist(), float4_div(), float4_mi(), float4_mul(), float4_pl(), float8_accum(), float8_combine(), float8_dist(), float8_div(), float8_mi(), float8_mul(), float8_pl(), float8_regr_accum(), float8_regr_combine(), gbt_float8_dist(), and pg_hypot().

float_underflow_error()

Definition at line 94 of file float.c.

95{

97 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

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

99}

References ereport, errcode(), errmsg(), and ERROR.

Referenced by dcbrt(), dcosh(), dexp(), dgamma(), dlog1(), dlog10(), dpow(), dsqrt(), dtof(), float4_div(), float4_mul(), float8_div(), float8_mul(), and pg_hypot().

float_zero_divide_error()

get_float4_infinity()

static float4 get_float4_infinity ( void ) inlinestatic

get_float4_nan()

static float4 get_float4_nan ( void ) inlinestatic

get_float8_infinity()

static float8 get_float8_infinity ( void ) inlinestatic

Definition at line 94 of file float.h.

95{

96#ifdef INFINITY

97

98 return (float8) INFINITY;

99#else

100

101

102

103

104

105

106 return (float8) (HUGE_VAL * HUGE_VAL);

107#endif

108}

Referenced by brin_minmax_multi_distance_float4(), brin_minmax_multi_distance_float8(), compute_range_stats(), datanh(), dcosh(), dsinh(), float8in_internal(), gbt_ts_dist(), get_distance(), gistindex_keytest(), initRectBox(), leftmostvalue_float8(), line_invsl(), line_sl(), NonFiniteIntervalPart(), NonFiniteTimestampTzPart(), numeric_float8(), pg_hypot(), point_invsl(), point_sl(), size_box(), spg_kd_inner_consistent(), spg_quad_inner_consistent(), and spgbeginscan().

get_float8_nan()

static float8 get_float8_nan ( void ) inlinestatic

Definition at line 123 of file float.h.

124{

125

126#if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))

127

129#else

130

131 return (float8) (0.0 / 0.0);

132#endif

133}

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcos(), dcosd(), dcot(), dcotd(), dgamma(), dpow(), dsin(), dsind(), dtan(), dtand(), float4_accum(), float8_accum(), float8_regr_accum(), float8in_internal(), hashfloat4(), hashfloat4extended(), hashfloat8(), hashfloat8extended(), line_closept_point(), numeric_float8(), numeric_float8_no_overflow(), pg_hypot(), and point_box_distance().

is_infinite()

Definition at line 118 of file float.c.

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}

References val.

extra_float_digits