Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110129 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19736 invoked from network); 11 May 2020 11:36:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2020 11:36:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5DCB51804F4 for ; Mon, 11 May 2020 03:13:15 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 May 2020 03:13:14 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id d21so1133241ljg.9 for ; Mon, 11 May 2020 03:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VN12QnboSnEGxp7z2+qJMP/cdWEdoiM5IgBXN2HSAVQ=; b=GMWLbiyzsqNJHmzesAN6w9rYxsIsCFIk3NzmfBNz2kclN8AMMKdi7umVZHea82iXqU 8MnYlROGWyV/VQFXjkFEVKmKSDVgaKXckqKZhhbjAy5wJOe+Qb1jJ/fqIZgpQakRWIlP pMPM/riQWWiWKuWF58RHVkaJjFkTTjpbFwiNJSLRrSEnxTRGM0Q24aTM2PlLJm2UXQhq 12JK5nCmg8R6DZV4VvU/VbMI/gUyHxBgxoHUYvSpmZLP1pdf8O26SRmD1bSU+sGhySmG 891LFdWqhiRYe9CZwPgr2bsWmnp5wwlVWugtsWo7f6K98zZzAZgtuDVvm1ReaIVNN0Uz IbEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VN12QnboSnEGxp7z2+qJMP/cdWEdoiM5IgBXN2HSAVQ=; b=btYdEjlt06ii6J+ZgD4OwMDV5Qh+MQIdbhFOtQ7UxR30g+wQ+kxu5bGdfeL35pvO6b XqQSj5aaloWuFVJVgG4aJqD22SSPLYFK3aAB1ZeXKo2gbzzDKaL7fJgLtm+n742uPwMe kgDS9Yj0NXcl5WHT14W4iEX3bRX6mMSbSkZgwwFtms7OiMk0I4d5xTV95exuCJflJONV KTlnFQa1v5uHLvEBMWxghlUL5sJ7GskOIBlGR4PwUgqzSrTnWL10T005muak9vXTnNDs 0PtGn7ot89kkI4nSrMWPLSIqOxeZdzSYE2rJUe7X/5ly9eA71p88yMdFsJ3+2iNQKLz9 5a/w== X-Gm-Message-State: AOAM531nLzCbLh1xTk9n+W13lpCHoUtFcR6z1WOcbz/5CLpdBXr0Yyw6 1oO6asISl9eVs/zYURBrfDqqQ4hDVGh/an57iRg= X-Google-Smtp-Source: ABdhPJwIYhhtinTlbjTtc/UFkQsVyhTZg9J0PWsb2RE7PV95viPqVVKPwqxwkqrV5im2pte1YUAtXlbPrlVDn4+BgE0= X-Received: by 2002:a2e:8884:: with SMTP id k4mr9994980lji.267.1589191993324; Mon, 11 May 2020 03:13:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 11 May 2020 12:12:57 +0200 Message-ID: To: "G. P. B." Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003df8e905a55c985c" Subject: Re: [PHP-DEV] printf() improvements From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003df8e905a55c985c Content-Type: text/plain; charset="UTF-8" On Thu, Apr 23, 2020 at 8:30 AM G. P. B. wrote: > On Wed, 22 Apr 2020 at 15:25, Nikita Popov wrote: > >> Hi internals, >> >> I'd like to make two improvements to the printf() functionality exposed by >> PHP (also affecting other variations like sprintf, vprintf, etc.) These >> improvements are motivated by >> https://wiki.php.net/rfc/locale_independent_float_to_string, which will >> make float to string casts locale insensitive, but not change the behavior >> of printf() specifiers. >> >> The proposed improvements are: >> >> 1. Support for the %h and %H specifiers, which behave the same as %g and >> %G, but are locale insensitive. These specifiers are already supported >> internally in PHP (though %h goes by the name of %k for reasons that are >> not relevant to userland) and is used for formatting floating-point >> numbers >> where case-sensitivity is not desired, such as for var_export(). >> >> 2. Support for * width and precision, in which case the width/precision is >> provided as an argument to printf(). This is a feature of printf() in C. >> >> The combination of these two features allows us to easily print floating >> point numbers exactly as PHP would print them: >> >> // Locale-sensitive using precision ini setting. >> sprintf("%.*G", ini_get('precision'), $float); >> >> // Locale-insensitive using serialize_precision ini setting. >> sprintf("%.*H", ini_get('serialize_precision'), $float); >> >> Notably, this also supports precision -1 (the default >> serialize_precision), >> which will pick the shortest accurate representation of the float. >> >> Without these features, it is actually quite hard to replicate PHP's exact >> behavior. The best approximation I've found is to print with %G at >> multiple >> precisions, pick out the shorted one and replace commas with dots on the >> assumption that comma is the only locale-specific decimal separator. It >> would be good to expose what PHP can already do directly. >> >> Implementations for the two features are available at >> https://github.com/php/php-src/pull/5432 and >> https://github.com/php/php-src/pull/5436. >> >> Regards, >> Nikita >> > > Seems like a no-brainer to add on my side. > > Best regards > > George P. Banyard > Any further feedback on this? Otherwise I'll merge these printf() improvements. Nikita --0000000000003df8e905a55c985c--