Return-Path: X-Original-To: apmail-pig-dev-archive@www.apache.org Delivered-To: apmail-pig-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1629C12966 for ; Sun, 11 May 2014 00:55:01 +0000 (UTC) Received: (qmail 99307 invoked by uid 500); 10 May 2014 23:33:16 -0000 Delivered-To: apmail-pig-dev-archive@pig.apache.org Received: (qmail 62885 invoked by uid 500); 10 May 2014 23:30:44 -0000 Mailing-List: contact dev-help@pig.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pig.apache.org Delivered-To: mailing list dev@pig.apache.org Received: (qmail 55495 invoked by uid 500); 10 May 2014 23:23:38 -0000 Delivered-To: apmail-hadoop-pig-dev@hadoop.apache.org Received: (qmail 22396 invoked by uid 99); 10 May 2014 23:05:14 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 May 2014 23:05:14 +0000 Date: Sat, 10 May 2014 23:05:14 +0000 (UTC) From: "Cheolsoo Park (JIRA)" To: pig-dev@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (PIG-3926) ROUND_TO function: rounds double/float to fixed number of decimal places MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PIG-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Cheolsoo Park updated PIG-3926: ------------------------------- Resolution: Fixed Status: Resolved (was: Patch Available) All patches committed to trunk. Note I removed a unused variable {{dbl}} in TestBuiltin.java while committing. Thank you Philip for the awesome work! > ROUND_TO function: rounds double/float to fixed number of decimal places > ------------------------------------------------------------------------ > > Key: PIG-3926 > URL: https://issues.apache.org/jira/browse/PIG-3926 > Project: Pig > Issue Type: New Feature > Affects Versions: 0.12.0 > Reporter: Philip (flip) Kromer > Assignee: Philip (flip) Kromer > Priority: Minor > Labels: builtin, function, math > Fix For: 0.13.0 > > Attachments: 0001-ROUND_TO-handles-nulls-accepts-rounding-mode.patch, 0001-Unit-tests-for-ROUND.patch, 0002-ROUND_TO-UDF-safely-rounds-values-to-given-precision.patch > > > The too-often used trick of rounding to a fixed number of decimal places by writing '1000 * Math.round(num / 1000.0)' is not only unsightly, it's numerically imprecise (http://stackoverflow.com/a/12684082/41857). The attached patch adds a function to do this. > ROUND_TO(val, digits) accepts a single float or double value, along with an integer number of digits, and returns the value to that number of decimal places > Examples: > {code} > ROUND_TO(3.14159f, 3) -- returns a float 3.142 > ROUND_TO(3.14159d, 0) -- returns a double 3.0. > {code} > I also added unit tests for ROUND -- there were none before that I could find. > I don't know how to write a unit test that the schema correctly routes to FloatRoundTo and DoubleRoundTo -- if the ones I provided are insufficient please point me to a simple example to emulate. -- This message was sent by Atlassian JIRA (v6.2#6252)