Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61876 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57866 invoked from network); 30 Jul 2012 14:12:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2012 14:12:05 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:42242] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/95-16347-43696105 for ; Mon, 30 Jul 2012 10:12:04 -0400 Received: by vcbgb30 with SMTP id gb30so5247070vcb.29 for ; Mon, 30 Jul 2012 07:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=R9WdKAP08InG982JczKGYpbXjP5zze9GoVn2NRHQjqc=; b=AYaeAi/4oAbK1mX+I6aWlXP/0Y6Xrm2KZvXaOPSHf3ibB8qXieiALqDTG7T3OHswGe HsfTd8aZkSvW8HoPXi7cbolJI/Y4kcUyCaaWs5hga+J+kWjzfPBuCpLdgM7mHKLRZPoe y7CDcBF0aLTKttlOmPXYwbY/T6CssWQXOgqBvAuGsQwvWICXUsGq20Q5FnFD96ntR82s 7OryagFKxIbcucSXbllU9K91SOgescZLV+xd4+Ziloa/Qfa/kH/ovcUGRX40yqqqAqjq Yih0Z0DZrgq/kGCJMV6RJgZg2psnP9KKwHvQgJk+dYCusb2+QwTTG08ICZrF6X8m2PZx 1FzA== Received: by 10.52.98.8 with SMTP id ee8mr9755904vdb.58.1343657522032; Mon, 30 Jul 2012 07:12:02 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.195.3 with HTTP; Mon, 30 Jul 2012 07:11:41 -0700 (PDT) In-Reply-To: References: Date: Mon, 30 Jul 2012 22:11:41 +0800 X-Google-Sender-Auth: v3bD4lalJCozkJsyUTVrvXvxnwE Message-ID: To: Devis Lucato Cc: PHP Developers Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] bug on bc math? From: laruence@php.net (Laruence) On Mon, Jul 30, 2012 at 9:52 PM, Laruence wrote: > Hi: > > I'd like mark this as a doc problem, see the comment of the bcmatch lib: > > /* The multiply routine. N2 times N1 is put int PROD with the scale of > the result being MIN(N2 scale+N1 scale, MAX (SCALE, N2 scale, N1 scale)). > */ > void bc_multiply (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC) > > and > > * Here is the full add routine that takes care of negative numbers. > N1 is added to N2 and the result placed into RESULT. SCALE_MIN > is the minimum scale for the result. */ > > void bc_add (n1, n2, result, scale_min) > > thanks Hi: but on the hand, we may also consider this as a bug, behavior not act like the doc said :) any IMO, fixing this, we should add some logic in PHP side, like before returning value to user . the code will look like(for bc_multiply): if (result->n_scale < scale ) { result->n_value = erealloc($result->n_value, scale); memset(result->n_result + result->n_scale, '0', scale - result->n_scale); result->n_scale = scale; } this will be a little ugly, since it alter the bc_num struct which should only inside bc lib, what do you think? thanks > > On Mon, Jul 30, 2012 at 8:47 PM, Devis Lucato wrote: >> Hi, >> >> before raising a bug I was wondering if anyone noticed this odd behavior in >> BC math functions ? >> >> Actual >> >> php -r "echo bcmul('1.1', '9.0', 5);" ==> 9.90 >> php -r "bcscale(5); echo bcmul('1.1', '9.0');" ==> 9.90 >> php -r "bcscale(5); echo bcadd('8.9', '1.0');" ==> 9.90000 >> >> >> Expected >> >> php -r "echo bcmul('1.1', '9.0', 5);" ==> 9.90000 >> php -r "bcscale(5); echo bcmul('1.1', '9.0');" ==> 9.90000 >> php -r "bcscale(5); echo bcadd('8.9', '1.0');" ==> 9.90000 >> >> >> Seen on 5.3 and 5.4. >> >> Looking at >> http://git.php.net/?p=php-src.git;a=history;f=ext/bcmath/bcmath.c;h=5dfafa8bd8dbc1703af2ea4452ac2b05b765a619;hb=HEADI >> couldn't see any recent change related to this bug. >> >> Thank you > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ -- Laruence Xinchen Hui http://www.laruence.com/