Re: [eigen] Indexes: why signed instead of unsigned? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Indexes: why signed instead of unsigned?
- From: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Mon, 10 May 2010 16:55:26 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Vtx35EgmTLY8wjqW3MrWAogA74xFRNpMriS5TWuhFws=; b=ECuPqewprJsotSml+CKc7KnoG1L/xiZLMayDgQY0v0r4dwPeWGN0FP2H83piO/6uUD uopCgkBdBKtU0oTofhSPr56wu7iAsroYXqofopFGdOW/rvKsGv9OiXZtrQGbzlLbSBmH sMxfUBGUl3qNXWqRGtUQRf785P5qs3CxBvAT8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ZLyVQBphfjdNEKHB+tIVcqc/yDfogyJxslNYwTU8vsEAQo0VNMtP22R/n/q0zL3rUs AML1RySMhODjl89PQDNRg0knXd/G3DdQASMXPhflWG8e6TzqtYnrin6pmjrqCS5lCokt prO++dbeiJWGired3GeC9yTSZdd3Eqc2Ddi8g=
On Mon, May 10, 2010 at 4:42 PM, Rui Maciel <rui.maciel@xxxxxxxxx> wrote:
>
> Benoit Jacob wrote:
>> See e.g. answer here:
>>
>> https://bitbucket.org/eigen/eigen/issue/106/index-and-size-type
>>
>> Benoit
>
>
> According to the example given in that answer, if we rely on a loop similar
> to:
>
> for(int col = cols() - 1; col>=0; --col)
>
>
> Does the cols() method deed to te signed? To put it in other words,
> independently of what value int col will assume throughout the loop, isn't the
> output of cols() always positive?
The problem is the decrement. The variable col (if e.g. unsigned int)
will reach 0 and then it will be decremented resulting in an underflow
(and a huge positive value) and an endless loop. If we changed cols()
and returned an int we would always need to cast and theoretically
take care that cols() fits into an int.
- Hauke