Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105455 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8453 invoked from network); 26 Apr 2019 12:32:02 -0000 Received: from unknown (HELO mout.gmx.net) (212.227.15.15) by pb1.pair.com with SMTP; 26 Apr 2019 12:32:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556271184; bh=iE5xu3ktTjFflNSPkD3RU88etbYpJTvIkfJNBx6ao/8=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=D4GPzIOHHIfQpq2Eo9lBks0pwOkUIswuqYPWbgoIkVQlRS4Zs4HHKB/8tHgM+R5gq 4Yj9OONpFpA1+pp22SuCgMBpdws4VELHhgw+1q1nBUdVENRIVfHgYqAaADxtjIe7JF Wn5GOIcgS+XLvoMMAcb5SsbCzcrXeiFHbzxUZ2kc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.2.144] ([79.222.45.225]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lh6sJ-1gyfVo3e4t-00oXR0; Fri, 26 Apr 2019 11:33:03 +0200 To: Benjamin Morel , Vladyslav Startsev Cc: "Legale.legale" , Ben Ramsey , PHP Internals References: <5c633ed8.1c69fb81.143ab.ad85@mx.google.com> Message-ID: <6a97cecf-7a5d-6476-7773-fdd41aa45646@gmx.de> Date: Fri, 26 Apr 2019 11:33:04 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:oqRyHlgDe5rzL6ZnIOihESJrhVxCrn/ZlH8ZgXL1xGAowmrMpZ1 77P84a3hL9G9tgzEvUchvYBd9NlfjQwQz3tKWUwoxfE1F3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OIVzPEjayc/nvTqU7KfMrZ9JuOptcH9zz7bF0i+EP5GBMfNKnt6fPsP7Uqj3zPuz8pgoo vz0ApXFjidA== Subject: Re: [PHP-DEV] Make bcmath functions more strict From: cmbecker69@gmx.de ("Christoph M. Becker") On 26.04.2019 at 09:45, Benjamin Morel wrote: >> I don't really understand it, I must be strict, converting to zero >> will lead to wrong calculations. > > That's what I said :) Fully agree here, any non-numeric string should th= row > an exception. > > In summary, I would check that the string matches ` > /^[\+\-]?[0-9]+(\.[0-9]+)?$/`or else throw an exception. Throwing an exception would be rather uncommon for functions, and would definitely have to wait for PHP 8 for BC reasons. Another option might be to introduce an object-oriented layer on top of libbcmath. A basic problem of the BC extension is that all functions accept strings, convert these to bc_nums[1], do the actual calculation, convert the bc_nums back to strings[2], and return these. This looks like quite some overhead, especially for more complex calculations where the intermediary results are not even needed as strings. If there is an OOP API, the conversion from string would only be needed in the constructor, and conversion to string only in the __toString() method. All intermediary calculations wouldn't need the from/to string conversions. And of course, users could switch to the OOP API if they desire, but could stick with the procedural API otherwise. An additional benefit might be that we sometime could switch away from the decimal storage[3] which appears to be mostly useful for the string conversions, but is otherwise wasteful (1 byte per decimal digit). [1] [2] [3] =2D- Christoph M. Becker