Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71003 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39263 invoked from network); 4 Jan 2014 21:49:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2014 21:49:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.51 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.51 mail-oa0-f51.google.com Received: from [209.85.219.51] ([209.85.219.51:38465] helo=mail-oa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/20-37367-00288C25 for ; Sat, 04 Jan 2014 16:49:54 -0500 Received: by mail-oa0-f51.google.com with SMTP id i7so17338354oag.24 for ; Sat, 04 Jan 2014 13:49:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Va0f/TOIyCx9YV65VBlOtIrbeWznt9NSSZvcPxBlOxI=; b=S3e9Ci30ReIujLXEn9ptXB3yiImEY3LJez5UXj06sYZLHLV+IjDmzSxGWoZzN03p/Y /UNrPh/bYTVoawN3qyZiZXYENRVvLnzHfW0ASSAe6rHiNzfTpy8reQOp88SwBG/zfG3p 5oY5KQVqp3i/+JV5oZVjsAa6YDbB0UJXgucFZh8xcq+R2nFzsis6wcDHHVExyOHSQD6r J4kRS9EReeyiTCA6hutTPMyZ7HBwlMnNlIhLcBMGjDvW0ogx5c5LsGlKrdWId2278kLK glL5JeVH4sLZ5/YuOgqItJOjOOmLfeOPBDeY0Obp5kep8NFttkEHHMXaelQNmUOtJLND fr1g== MIME-Version: 1.0 X-Received: by 10.60.61.14 with SMTP id l14mr65474998oer.18.1388872190068; Sat, 04 Jan 2014 13:49:50 -0800 (PST) Received: by 10.182.54.112 with HTTP; Sat, 4 Jan 2014 13:49:50 -0800 (PST) In-Reply-To: References: Date: Sat, 4 Jan 2014 22:49:50 +0100 Message-ID: To: Yasuo Ohgaki Cc: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=001a113306f2870cf004ef2c0176 Subject: Re: [PHP-DEV] [RFC] Floating Point support in GMP extension From: nikita.ppv@gmail.com (Nikita Popov) --001a113306f2870cf004ef2c0176 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Jan 4, 2014 at 9:38 PM, Yasuo Ohgaki wrote: > My only concern is GMP float and int conversion. > I prefer to have result > > 10 / 3 = 3 > > and > > 10.0 / 3 = 3.33333333333333333333333(to GMP precision) > > I prefer to have INT result for "INT op INT" and float result for "FLOAT op > INT". Huge integer arithmetic has it's own usage and converting int to > float automatically is not nice, since it breaks goodies of GMP int. I hope > everyone prefer this behavior. > I agree with this, pure-int operations should have a pure-int result. Making GMP(10) / GMP(3) return a float now would also be fatal in case we want to later introduce support for rationals or decimals in GMP (which could just as well be the result of 10/3). On the same note I'd also suggest to call the ini setting gmp.default_float_precision (to disambiguate from a potential gmp.default_decimal_precision in the future). Some more thoughts / suggestions: * I would consider not making the type an internal flag exposed via gmp_isint() and gmp_isfloat() methods, but use two different class entries for them. I.e. have GmpInt and GmpFloat (as the GMP class name is not released yet, we can still nicely do this change). Maybe with a GmpNumber supertype implemented by all current and future GMP types. This would make dumps/serialization more obvious and forward-compatible, allow typehints, etc. Type can then be checked with $n instanceof GmpInt or $n instanceof GmpFloat (though one could still add the gmp_isint and gmp_isfloat functions, not sure how useful they would be though). This especially seems like the way to go if we want to add more GMP number types in the future (will prevent us from having an "int or float or decimal or rational" type...) * The gmp_init_float() should likely also have a precision parameter. Given that non-decimal floating point bases are a rarity (?), maybe put it before the base argument? * You'll likely need something like gmp_float_random() to accompany gmp_random(). (Hopefully using a sane parameter without limb size dependence ;) * Additionally to gmp_cmp I'd also add a function gmp_float_equals or gmp_float_eq which exposes mpf_eq. Comparing floats is always a PITA and exposing that functionality would be greatly helpful ;) * Is there any way to get rid of the locale-dependent behavior of mpf_set_str? This sounds like it could be a big pain. (Especially given how gmp floats are not what you use with your average user input, so seems little useful.) That's it ... for now :) Nikita --001a113306f2870cf004ef2c0176--