Commit c3f3b7a
authored
fix: Avoid precision loss for
## Which issue does this PR close?
- Closes #22514.
## Rationale for this change
`atan2` defined two input signatures: `(Float32, Float32)` and
`(Float64, Float64)` (in that order). That meant that integer inputs
were coerced into `Float32` values, which lead to incorrect results:
`atan2(1, 1000000)` resulted in less precision than `atan2(1.0,
1000000.0)`; the results for the former were also inconsistent with the
behavior of `atan2` in Postgres and DuckDB.
Fix this by only using the `Float32` path when given two` Float32`
inputs; for other inputs, we should use `Float64`. This avoids rounding
for large integer inputs (`Float32` has only 24 mantissa bits, so larger
integers would get rounded).
## What changes are included in this PR?
* Fix `atan2` signature to only take the `Float32` code path for two
`Float32` inputs
* Update SLT, add new SLT test
## Are these changes tested?
Yes, new test added.
## Are there any user-facing changes?
Yes: the return type and semantics of `atan2` in some circumstances has
changed. `atan2` will now only be computed in `Float32` when passed two
`Float32` values. In all other cases, the computation will be done in
`Float64` and a `Float64` value will be returned.atan2 with integer args (#22516)1 parent e292f33 commit c3f3b7a
4 files changed
Lines changed: 50 additions & 28 deletions
File tree
- datafusion
- functions/src
- math
- sqllogictest/test_files
- docs/source/user-guide/sql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | 248 | | |
250 | 249 | | |
251 | 250 | | |
252 | | - | |
| 251 | + | |
253 | 252 | | |
254 | 253 | | |
255 | 254 | | |
| |||
270 | 269 | | |
271 | 270 | | |
272 | 271 | | |
273 | | - | |
274 | 272 | | |
275 | 273 | | |
276 | 274 | | |
| |||
345 | 343 | | |
346 | 344 | | |
347 | 345 | | |
348 | | - | |
349 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
350 | 352 | | |
351 | 353 | | |
352 | 354 | | |
| |||
365 | 367 | | |
366 | 368 | | |
367 | 369 | | |
368 | | - | |
369 | 370 | | |
370 | 371 | | |
371 | 372 | | |
| |||
379 | 380 | | |
380 | 381 | | |
381 | 382 | | |
382 | | - | |
383 | 383 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
389 | 395 | | |
390 | 396 | | |
391 | 397 | | |
| |||
402 | 408 | | |
403 | 409 | | |
404 | 410 | | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
| 411 | + | |
| 412 | + | |
410 | 413 | | |
411 | 414 | | |
412 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
238 | 257 | | |
239 | 258 | | |
240 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
0 commit comments