Thanks for pointing out the problems, particularly the a>b issue.  I've
reworked that section.

On Thu, Sep 18, 2014 at 4:57 AM, Gunnar Farnebäck <[email protected]>
wrote:

> There are still three arguments to max in the last of those examples.
> Actually it's not clear that you can make an equivalent expression with min
> and max. Functionally (with intended use)
> x[i] = max(a, min(b, x[i]))
> does the same thing as the earlier examples but it expands to
> x[i] = ifelse(ifelse(b < x[i], b, x[i]) < a, a, ifelse(b < x[i], b, x[i]))
> which should be hard for a compiler to optimize to the earlier examples
> since they don't give the same result in the degenerate case of a > b.
>
> A closer correspondence is given by the clamp function which is
> implemented as a nested ifelse in the same way as example 2 (although in
> the opposite order, so it also differs for a>b).
>
> Den onsdagen den 17:e september 2014 kl. 16:28:45 UTC+2 skrev Arch Robison:
>>
>> Thanks.  Now fixed.
>>
>> On Wed, Sep 17, 2014 at 4:14 AM, Gunnar Farnebäck <[email protected]>
>> wrote:
>>
>>> In the section "The Loop Body Should Be Straight-Line Code", the first
>>> and second code example look identical with ifelse constructions. I assume
>>> the first one should use ? instead. Also the third code example has a stray
>>> x[i]<a argument to the max function.
>>>
>>

Reply via email to