diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2015-03-28 09:22:51 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2015-03-28 09:22:51 -0400 |
commit | cfe12763c32437bc708a64ce88a90c7544f16185 (patch) | |
tree | 62c519e8127729d9b43c536adc1296debb90318b /contrib/pg_stat_statements/pg_stat_statements.c | |
parent | 3a20b0e7b6dae48cd6be1257e9017663f1402b91 (diff) | |
download | postgresql-cfe12763c32437bc708a64ce88a90c7544f16185.tar.gz postgresql-cfe12763c32437bc708a64ce88a90c7544f16185.zip |
Use standard librart sqrt function in pg_stat_statements
The stddev calculation included a faster but unportable sqrt function.
This is not worth the extra effort, and won't work everywhere. If the
standard library function is good enough for the SQL function it
should be good enough here too.
Diffstat (limited to 'contrib/pg_stat_statements/pg_stat_statements.c')
-rw-r--r-- | contrib/pg_stat_statements/pg_stat_statements.c | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index fee2aaacbe2..da6c242631a 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -57,6 +57,7 @@ */ #include "postgres.h" +#include <math.h> #include <sys/stat.h> #include <unistd.h> @@ -326,7 +327,6 @@ static char *generate_normalized_query(pgssJumbleState *jstate, const char *quer int *query_len_p, int encoding); static void fill_in_constant_lengths(pgssJumbleState *jstate, const char *query); static int comp_location(const void *a, const void *b); -static inline double sqrtd(const double x); /* @@ -1583,7 +1583,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, */ if (tmp.calls > 1) values[i++] = - Float8GetDatum(sqrtd(tmp.sum_var_time / tmp.calls)); + Float8GetDatum(sqrt(tmp.sum_var_time / tmp.calls)); else values[i++] = Float8GetDatum(0.0); } @@ -2968,20 +2968,3 @@ comp_location(const void *a, const void *b) else return 0; } - -/* - * fast sqrt algorithm: reference from Fast inverse square root algorithms. - */ -static inline double -sqrtd(const double x) -{ - double x_half = 0.5 * x; - long long int tmp = 0x5FE6EB50C7B537AAl - ( *(long long int*)&x >> 1); - double x_result = * (double*)&tmp; - - x_result *= (1.5 - (x_half * x_result * x_result)); - /* If retry this calculation, it becomes higher precision at sqrt */ - x_result *= (1.5 - (x_half * x_result * x_result)); - - return x_result * x; -} |