Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion stylistic question

Received: by 10.180.96.6 with SMTP id do6mr879452wib.1.1353058830955;
        Fri, 16 Nov 2012 01:40:30 -0800 (PST)
Path: ha8ni293004wib.1!nntp.google.com!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!news-hub.siol.net!news1.t-com.hr!newsfeed.CARNet.hr!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From: Stephen Sprunk <step...@sprunk.org>
Newsgroups: comp.lang.c
Subject: Re: stylistic question
Date: Sat, 10 Nov 2012 21:12:43 -0600
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <k7n53c$etl$1@dont-email.me>
References: <k7mgn4$sh$1@dont-email.me> <k7mm6e$t6$1@dont-email.me> <slrn3vfsk9todo.kq9.ike@iceland.freeshell.org>
Mime-Version: 1.0
Injection-Date: Sun, 11 Nov 2012 03:12:44 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="60314493f4bcbcd67a6972774449ca58";
	logging-data="15285"; mail-complaints-to="ab...@eternal-september.org";	posting-account="U2FsdGVkX19L0IQebOpvKsnu2gqmf6ZD"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:10.0) Gecko/20120206 Thunderbird/10.0
In-Reply-To: <slrn3vfsk9todo.kq9.ike@iceland.freeshell.org>
Cancel-Lock: sha1:wfq4DTowswyNTDC9Apd6eN3/5yw=
Bytes: 2493
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

On 10-Nov-12 17:22, Ike Naar wrote:
> On 2012-11-10, Stephen Sprunk <step...@sprunk.org> wrote:
>> On 10-Nov-12 15:24, Bill Cunningham wrote:
>>> #include <stdio.h>
>>>
>>> double t_range(double hi, double low, double pc)
>>> {
>>>     double ans1, ans2, ans3;
>>>     ans1 = ans2 = ans3 = 0.0;
>>>     ans1 = hi - low;
>>>     ans2 = pc - low;
>>>     ans3 = hi - pc;
>>>     if (ans1 > ans2 && ans1 > ans3)
>>>         return ans1;
>>>     else if (ans2 > ans3 && ans2 > ans1)
>>>         return ans2;
>>>     else if (ans3 > ans2 && ans3 > ans1)
>>>         return ans3;
>>>     else {
>>>         return -1;
>>>     }
>>> }
>>
>> That's a decent literal translation of the requirements, except
>> the "else"s aren't necessary since the "then" path doesn't fall
>> through, and your temporary variable names aren't very informative.
>> I also wonder if it's possible to reach the "return -1;" path at
>> all.
> 
> When the two largest ans* values are equal.

True, the above code fails to meet the specification (by returning -1)
if pc==hi and/or pc==low.  Good catch.

S

-- 
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS        dice at every possible opportunity." --Stephen Hawking