Make printf trim trailing zeroes with %[Gg] format #458
No reviewers
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!458
Loading…
Reference in a new issue
No description provided.
Delete branch "MCJack123/patch-1"
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?
This PR modifies the behavior of
pico_printfto automatically trim trailing zeroes when using the%Gor%gformat specifiers. This is the behavior that is specified by GCC:Previously,
printf("%.14g", 2000)would output2000.0000000000, but with this change it outputs just2000. This is useful for programs that want the minimum-length conversion of a number with the most precision necessary. (My example is Lua, which usessprintf(s, "%.14g", num)to convert numbers to strings; previously this would result in unnecessarily large conversions for small integers.)This change does not affect the default
printf- newlib exhibits the same behavior aspico_printfcurrently does, so that would have to be adjusted as well (and I can say after reading the code that I'm not the one to do that). Users will have to linkpico_printfmanually to benefit AFAICT.Please let me know if this breaks anything - I didn't have a chance to test this fully (I'm embroiled in debugging some other stuff), but looking at the code I don't think there should be much to break.
Note that people using the SDK CMake build get pico_printf by default.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.