Post Reply 
(41) Round To The Nearest 1/n
04-15-2018, 04:13 PM (This post was last modified: 04-15-2018 04:15 PM by Dieter.)
Post: #7
RE: (41) Round To The Nearest 1/n
(04-14-2018 08:09 PM)Mike (Stgt) Wrote:  For positive n do doubt. Same for negative n? Sure? How did you prove that?

Simple. We are looking for a value of z for which z/n is as close to x as possible. The program then returns z/n. If n<0 then z has to have the opposite sign of x.

In simple words: z has to be an integer, but it doesn't have to be a natural number.
In our example \(\pi\) rounded to the nearest –1/16 is 3,125, which is –49/–16. Or z=–49.
The essential point here: \(z\in\mathbb{Z}\) and not only \(z\in\mathbb{N}\).

On the other hand –3,125 cannot be the correct answer as it isn't the closest –1/16 at all. Even 0 is closer to \(\pi\) than –3,125. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (41) Round To The Nearest 1/n - hth - 04-12-2018, 06:12 PM
RE: (41) Round To The Nearest 1/n - Dieter - 04-12-2018, 06:57 PM



User(s) browsing this thread: 1 Guest(s)