You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/10/31 23:00:28 UTC
[jira] [Commented] (GROOVY-7652) Float/Double trunc methods round
down for negative values
[ https://issues.apache.org/jira/browse/GROOVY-7652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14984178#comment-14984178 ]
ASF GitHub Bot commented on GROOVY-7652:
----------------------------------------
GitHub user jwagenleitner opened a pull request:
https://github.com/apache/incubator-groovy/pull/171
GROOVY-7652 - Float/Double trunc methods perform rounding for negative values
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/jwagenleitner/incubator-groovy GROOVY-7652
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-groovy/pull/171.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #171
----
commit b93926c52245f4ba45eb7529784d71e06fd83a16
Author: John Wagenleitner <jo...@gmail.com>
Date: 2015-10-31T20:45:05Z
GROOVY-7652 - Float/Double trunc methods perform rounding for negative values
----
> Float/Double trunc methods round down for negative values
> ---------------------------------------------------------
>
> Key: GROOVY-7652
> URL: https://issues.apache.org/jira/browse/GROOVY-7652
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.5
> Reporter: John Wagenleitner
> Priority: Minor
>
> The {{trunc}} methods on Float/Double use the {{Math.floor}} method for all values, however for negative values this causing rounding down. I think for negative values {{Math.ceil}} needs to be used.
> Here are some asserts to show the rounding:
> {code}
> Float f = -123.739f
> Double d = -123.739d
> assert -123f == f.trunc() // fails: -124
> assert -123d == d.trunc() // fails: -124
> assert -123.73f == f.trunc(2) // fails: -123.74
> assert -123.73d == d.trunc(2) // fails: -123.73
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)