get a value as an int, tell if there is a problem */
| 1862 | |
| 1863 | /* get a value as an int, tell if there is a problem */ |
| 1864 | static bool |
| 1865 | coerceToInt(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 */ |
| 1892 | static bool |
no test coverage detected