From: "Earlopain (Earlopain _) via ruby-core" Date: 2026-05-31T20:02:42+00:00 Subject: [ruby-core:125594] [Ruby Bug#22087] Octal format specifier in alternatve form ignores zero precision if value is zero Issue #22087 has been updated by Earlopain (Earlopain _). Status changed from Open to Rejected Ah, indeed. It looked it up an you are right. From https://en.cppreference.com/c/io/fprintf x/X: > In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. o: > In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. ---------------------------------------- Bug #22087: Octal format specifier in alternatve form ignores zero precision if value is zero https://bugs.ruby-lang.org/issues/22087#change-117429 * Author: Earlopain (Earlopain _) * Status: Rejected * ruby -v: ruby 4.1.0dev (2026-05-29T14:34:40Z master 7a07a54298) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- For integer types, it is documented that zero as a value results in empty output: https://docs.ruby-lang.org/en/4.0/language/format_specifications_rdoc.html#:~:text=If%20the%20precision%20is%200%20and%20the%20value%20is%200%2C%20nothing%20is%20written This applies when `#` is not given. But with `#`, the octal format violates that statement: ```rb pp sprintf("%#.0b", 0) # => "" pp sprintf("%#.0B", 0) # => "" pp sprintf("%#.0x", 0) # => "" pp sprintf("%#.0X", 0) # => "" pp sprintf("%#.0o", 0) # => "0" ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/