<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div dir="auto" style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
My latest thoughts; please advise if I have misunderstood anything.</div>
<div dir="auto" style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<br>
</div>
<div dir="auto" style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<br>
<div>
<blockquote type="cite">
<div>On Jan 24, 2025, at 3:11 AM, Jan Kowalski <jan7493@gmail.com> wrote:</div>
<div>
<div dir="ltr">
<div><br>
<div>I'd say that, if it's possible, we should reduce the arithmetic artifacts, rather than introduce them through not really needed, and not visible at the first sight, type conversions.</div>
<div><br>
</div>
<div>… Do you think introducing such change would be beneficial to simplify the code, or rather introduce minor precision improvement, while we still don’t have 100% decimal precision?</div>
</div>
</div>
</div>
</blockquote>
</div>
<div><br>
</div>
<div>Okay, so what we’re looking for is a way to convert floats to BigDecimals in such a way that `0.1f` comes out the same as `new BigDecimal(“0.1”)`.</div>
<div><br>
</div>
<div>This thread is characterizing that outcome as “reducing artifacts” and “improving precision”, which seems fair on the surface, but I believe this is more like an illusion. I think the reason this looks like obvious “improvement” to us is only because we
happen to be using <i>literals</i> in our examples. But for a float value that isn’t a literal, like our friend `0.1f + 0.2f`, I think that the illusion is shattered. I think this “exposes" that the scale chosen by BD.valueOf(double) is based on an “artifact”
of that value that isn’t really meant to be “information carried by” the value. (Were we to think the latter way, it makes us think of a float-to-double cast as
<i>losing information</i>, which feels like nonsense.)</div>
<div><br>
</div>
<div>I think the fact that a new overload would affect current behavior means we need to rule that option out. I don’t think this is a case that can justify that cost. So it would at best have to be a new separately-named method like `valueOfFloat`. So at best
this issue will <i>still</i> bite users of `valueOf`, and we would still want the documentation of that method to advise users on what to do instead.</div>
<div><br>
</div>
<div>My feeling is that all we need it to do is advise the user to call `BigDecimal.valueOf(Float.toString(val))`. This is very transparent about what’s really happening. Here the user is intentionally
<i>choosing</i> the representation/scale.</div>
<div><br>
</div>
<div>I personally don’t see this as a case where fast-enough benchmark result would justify adding a new method.</div>
<div><br>
</div>
<div>Your thoughts?</div>
</div>
</body>
</html>