On Mon, Mar 15, 2010 at 9:17 PM, Roger Hui <[email protected]> wrote: > How is that being consistent? A (relative) tolerance > of 1 does not give useful results. > http://www.jsoftware.com/jwiki/Essays/Tolerant_Comparison#ToleranceLessThan1 > > ----- Original Message ----- > From: Zsbán Ambrus <[email protected]> > Date: Monday, March 15, 2010 11:10 > Subject: Re: [Jchat] [Jprogramming] Request for enhancement to # > To: [email protected] >> >> As for elegant and consistent notations, could we have monadic >> <.!.1mean rounding to the nearest integer?
Let me explain. For small real numbers, tolerant floor gives a number greater than the input if that result is tolerantly equal to the input. For example, with the default precision, this rounds up because 20 is tolerantly equal to the input <.20-1e_12 20 20=20-1e_12 1 but this rounds down because 10 is not tolerantly equal to the input <.10-1e_12 9 10=10-1e_12 0 For large real numbers however, this rule would not make sense. A large real number is tolerantly equal to many different integers, eg. 9!:11]16 (=_18+<.)1e15%3 1 (=19+<.)1e15%3 1 yet floor rounds this number down to 333333333333333, even though if it rounded it up to 333333333333334 that would also be tolerantly equal to the input: (,<.)1e15%3 333333333333333.3 333333333333333 The rule here is that if the input of floor is a large real number, then it rounds the output to the nearest integer: (,<.)0.3+1e15%3 333333333333333.6 333333333333334 Now consider the hypothetical <.!.1 monad I suggested. This uses such a large tolerance that any input would count as large, because any real number is tolerantly equal to many integers with this tolerance. Thus, extending the above this would have to round any real number to the nearest integer. Now as for your suggestion, > As well, <.0.5+y already rounds y to the nearest integer. that's a good workaround for most cases, but of course <.!.0]0.5+y would be more precise, <.0.5+ 10.5-1e_15 11 <.!.0]0.5+ 10.5-1e_15 10 (and even that would behave differently from the hypothetical <.!.1 for numbers that are exactly 0.5 larger than an even integer.) Thus, the suggested <.!.1 verb would be shorter and easier to write than even <....@+&0.5 in most cases, and it would be guaranteed to give the right result even in the rare edge cases. Ambrus ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
