powf(10, -11) is not accurate #1566
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#1566
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background: trying to solve a floating-point accuracy issue in MicroPython running on RP2040: https://github.com/micropython/micropython/issues/13094
There seems to be an accuracy issue with the computation done by
powffor certain arguments. In particular we see issues withpowf(10, -11).Code to reproduce:
The second set of prints shows the issue when
volatile int expis used, which forces the evaluation to go through the fullpowffunction (otherwise the compiler may optimise it out).The results I get on a standard Pico with pico-sdk 1.5.1:
The first two lines are correct (actually the second one is out by an LSB, it should be
b8:43:ba:51). The third line is quite inaccurate, out by 4 LSBs.The bug seems to be in the implementation of
fpowint_1()andfpow_int2(), it looks like the latter is accumulating an error in its recursion.This is what I get running on ubuntu
Spraying a few doubles around gets you this on Pico...
See the fix suggested here: https://github.com/micropython/micropython/issues/13094#issuecomment-1837652290
That computes the reciprocal first, then the power.