[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why is there no 'math.round'?
- From: askok@...
- Date: Wed, 23 Apr 2008 17:57:23 +0300
I am in the position to help a customer transition to Lua,
and I'm sure they'll ask question s.a. where's "round"
when we start going specific.
And since I didn't have the reason for abandoning 'round'
I wanted to ask. That's all.
The specific variant I'd like to have is
function round( v, step )
return math.floor( v*step +0.5 ) / step
This is the kind of things that just should "be there" (as
most is, already). Maybe I'll just inject a 'math.round'
to them myself, to avoid sticking to this issue and
focusing on the language itself, instead.
Mark Hamburg nailed the reasoning right:
In adding a rounding function, there's a disincentive to add it to math itself because the Lua distribution conceptually controls that namespace. So one adds mymath.round. (Lightroom has AgMathUtils.round.) But then everyone goes off and re-invents this and when one wants to share code we run into problems.
The round above already causes a clash compared to the one
on the Wiki (2nd param works differently).
On Wed, 23 Apr 2008 10:43:02 -0400
"Mike Crowe" <email@example.com> wrote:
What's the specific request that we are trying to
precision) for non-integer rounding?
I'm confused about what is being requested. I agree
with the earlier
observation that floor/ceil give us everything we need:
a = 12.345678
Am I missing something very obscure?