MCPcopy Create free account
hub / github.com/apache/cloudberry / coerceToInt

Function coerceToInt

src/bin/pgbench/pgbench.c:1864–1889  ·  view source on GitHub ↗

get a value as an int, tell if there is a problem */

Source from the content-addressed store, hash-verified

1862
1863/* get a value as an int, tell if there is a problem */
1864static bool
1865coerceToInt(PgBenchValue *pval, int64 *ival)
1866{
1867 if (pval->type == PGBT_INT)
1868 {
1869 *ival = pval->u.ival;
1870 return true;
1871 }
1872 else if (pval->type == PGBT_DOUBLE)
1873 {
1874 double dval = rint(pval->u.dval);
1875
1876 if (isnan(dval) || !FLOAT8_FITS_IN_INT64(dval))
1877 {
1878 pg_log_error("double to int overflow for %f", dval);
1879 return false;
1880 }
1881 *ival = (int64) dval;
1882 return true;
1883 }
1884 else /* BOOLEAN or NULL */
1885 {
1886 pg_log_error("cannot coerce %s to int", valueTypeName(pval));
1887 return false;
1888 }
1889}
1890
1891/* get a value as a double, or tell if there is a problem */
1892static bool

Callers 1

evalStandardFuncFunction · 0.85

Calls 1

valueTypeNameFunction · 0.85

Tested by

no test coverage detected