What Data Type is Returned by a Mathematical Function?

Just earlier today, I was using POW(), which I’ve grown quite fond of, simply because it makes life easier. I prefer using it like SELECT 512*POW(1024,2) to find out the number of bytes to put in a variable, for example.

Oh, so all of a sudden, it’s a double. I do agree with this though, as the value should be a double, but shouldn’t this be documented somewhere?

Now, for my original purpose, I can do something like this to set my variable: SET GLOBAL <variable> = CAST(512*POW(1024,2) AS UNSIGNED); — which will work, or even SET GLOBAL <variable> = 512 * ABS(1024*1024);, or perhaps you’d prefer the more “standard” method: SET GLOBAL <variable> = 512 *1024*1024;.

Also, it seems the default message for a DOUBLE exceeding 1.7976931348623157E+308 has changed between versions 5.0.67 and 6.0.6:

I’m not sure which one I prefer, really. inf is not really correct, as there can be a larger value (for example, to the power of 17 instead of 16, in this case) but is NULL right? NULL doesn’t sound right to me, I would prefer something like a SQL error here, something like “Error: Value out of bounds”.

Let’s get back to how to find out a data type returned by a function. Sure, we can take a look at the source. But, when I go to the documentation, I would really like to see what is the data type being returned.

Let’s take another example, the ABS() function — it should return the absolute value, but what’s the data type? Performing the same task as with POW() we get a few different results: