You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Heinrich Bohne (JIRA)" <ji...@apache.org> on 2019/07/03 19:12:00 UTC
[jira] [Created] (NUMBERS-128) Precision of Fraction.floatValue()
can be improved
Heinrich Bohne created NUMBERS-128:
--------------------------------------
Summary: Precision of Fraction.floatValue() can be improved
Key: NUMBERS-128
URL: https://issues.apache.org/jira/browse/NUMBERS-128
Project: Commons Numbers
Issue Type: Improvement
Components: fraction
Affects Versions: 1.0
Reporter: Heinrich Bohne
The current implementation of {{Fraction.floatValue()}} first calls {{doubleValue()}}, which converts the fraction to a {{double}} with maximum possible precision, and then rounds the returned {{double}} value to a {{float}}. For the fraction 1 + 2^6^ / (2^30^ - 1) = (2^30^ - 1 + 2^6^) / (2^30^ - 1), this yields a result of exactly 1. However, the [actual value of the fraction|https://www.wolframalpha.com/input/?i=(2%5E30+-+1+%2B+2%5E6)%2F(2%5E30+-+1)+to+base+2] is closer to 1 + 2^-23^ (which is representable exactly as a {{float}}) than it is to 1, as WolframAlpha [confirms|https://www.wolframalpha.com/input/?i=abs((2%5E30+-+1+%2B+2%5E6)%2F(2%5E30+-+1)+-+(1+%2B+2%5E-23))+%3C+abs((2%5E30+-+1+%2B+2%5E6)%2F(2%5E30+-+1)+-+1)].
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)