Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 19914 invoked from network); 22 Aug 2009 15:27:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Aug 2009 15:27:16 -0000 Received: (qmail 7509 invoked by uid 500); 22 Aug 2009 15:27:37 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 7389 invoked by uid 500); 22 Aug 2009 15:27:36 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 7376 invoked by uid 99); 22 Aug 2009 15:27:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 15:27:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 15:27:35 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id E346F234C052 for ; Sat, 22 Aug 2009 08:27:14 -0700 (PDT) Message-ID: <1154989109.1250954834930.JavaMail.jira@brutus> Date: Sat, 22 Aug 2009 08:27:14 -0700 (PDT) From: "Henri Biestro (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (JEXL-87) Inconsistent behaviour of arithmetical operations In-Reply-To: <867315699.1250765235298.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/JEXL-87?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12746469#action_12746469 ] Henri Biestro commented on JEXL-87: ----------------------------------- About literals, it could be convenient & easy to add syntactic notations for the different literal types : 123L for (Long) 123 12.3d for Double 12.3D for BigDecimal (capital 'D')) 123I for BigInteger (capital 'I') On the arithmetic itself, it might be easier on the user-end to follow more common rules about types by avoiding automatic conversion & add coercion operators (or functions in the global namespace) - applying the "lesser surprise principle". The "more common rules" would be composition rules based on a usual datatype ordering: String > BigDecimal > Double > BigInteger > Long > Character > Int > Short > Byte And all operations would do: x o y -> Compose(type(x), type(y)).o (x,y) With compose being: Compose(Double, BigInteger) -> BigDecimal Composte(t1, t2) -> Datatype.Max(t1, t2) And each datatype implement its own code for each operation. Since arithmetic operations could then overflow, we'd introduce explicit coercions to let users circumvent these cases. I however suspect such a scheme would be further away from the JSF/JSP EL spec. WDYT ? > Inconsistent behaviour of arithmetical operations > ------------------------------------------------- > > Key: JEXL-87 > URL: https://issues.apache.org/jira/browse/JEXL-87 > Project: Commons JEXL > Issue Type: Bug > Reporter: Sebb > Fix For: 2.0 > > > BigInteger(7) / BigInteger(2) == 3 > whereas > BigDecimal(7) / BigDecimal(2) == 4, because the result is rounded up. > I would expect the results to be the same. > Rather worse is: > BigDecimal(7) % BigDecimal(2) == -1 > which makes no sense at all. > Seems to me that the arithmetic "rules" need revisiting and rationalising - for example why should Integer be treated as double? > At present literal numbers are treated as Integer or Float; there's no option to generate Long or Double literals. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.