Re: BUG #18390: exponentiation produces float datatype, but nth-root produces integer
От | Tom Lane |
---|---|
Тема | Re: BUG #18390: exponentiation produces float datatype, but nth-root produces integer |
Дата | |
Msg-id | 2043864.1710339130@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: BUG #18390: exponentiation produces float datatype, but nth-root produces integer ("David G. Johnston" <david.g.johnston@gmail.com>) |
Список | pgsql-bugs |
"David G. Johnston" <david.g.johnston@gmail.com> writes: > On Tuesday, March 12, 2024, PG Bug reporting form <noreply@postgresql.org> > wrote: >> However, an nth-root calculation from that float result does NOT produce a >> new float result: > The issue is you expect dividing two integers to produce a float but that > isn’t how that works. Dividing two integers produces an integer. In this > case zero, or .1 rounded down/truncated. Possibly adding to the OP's confusion: not one of these examples contains any float arithmetic whatsoever. They're of type numeric. =# select pg_typeof(2.5937424601000000^(1.0/10)); pg_typeof ----------- numeric (1 row) See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS-NUMERIC which says A numeric constant that contains neither a decimal point nor an exponent is initially presumed to be type integer if its value fits in type integer (32 bits); otherwise it is presumed to be type bigint if its value fits in type bigint (64 bits); otherwise it is taken to be type numeric. Constants that contain decimal points and/or exponents are always initially presumed to be type numeric. A cast to float would occur only if the value is fed to an operator that doesn't come in an exactly matching datatype. regards, tom lane
В списке pgsql-bugs по дате отправления: