> +unsigned clamp_dim(unsigned dim)
> +{
> + return std::min<unsigned long>(std::numeric_limits<long>::max(), dim);
> +}
>
> There's a mix of types here: unsigned int, unsigned long and signed long,
> which is causing me problems understanding. I know sizeof(unsigned int) <=
> sizeof(long), which implies to me that
>
> dim <= std::numeric_limits<unsigned>::max()
> <= std::numeric_limits<long>::max()
when, as Brandon encountered on armhf, long and int are the same size.
> so the min() will always choose "dim". So I don't understand what it is
> clamping to.
In the above case it is clamping to std::numeric_limits<long>::max()
> +// For our convenience when doing calculations we clamp the dimensions of the
> aspect ratio
> +// so they will fit into a long without overflow.
> What "long"? AspectRatio is a pair of unsigned ints.
If std::numeric_limits<long>::max() <= dim <= std::numeric_limits<unsigned>::max() then dim doesn't fit in a long.
> +unsigned clamp_dim(unsigned dim) :numeric_ limits< long>:: max(), dim); limits< unsigned> ::max() limits< long>:: max()
> +{
> + return std::min<unsigned long>(std:
> +}
>
> There's a mix of types here: unsigned int, unsigned long and signed long,
> which is causing me problems understanding. I know sizeof(unsigned int) <=
> sizeof(long), which implies to me that
>
> dim <= std::numeric_
> <= std::numeric_
when, as Brandon encountered on armhf, long and int are the same size.
std: :numeric_ limits< long>:: max() <= std::numeric_ limits< unsigned> ::max()
> so the min() will always choose "dim". So I don't understand what it is
> clamping to.
In the above case it is clamping to std::numeric_ limits< long>:: max()
> +// For our convenience when doing calculations we clamp the dimensions of the
> aspect ratio
> +// so they will fit into a long without overflow.
> What "long"? AspectRatio is a pair of unsigned ints.
If std::numeric_ limits< long>:: max() <= dim <= std::numeric_ limits< unsigned> ::max() then dim doesn't fit in a long.