digitalmars.D.learn - vrp bug?
- Kagamin (9/9) Jun 14 ```
- Forum User (16/26) Jun 14 ```
- Kagamin (1/1) Jun 15 If b<10, `'0'+b` is returned.
- Dukc (7/17) Aug 31 I believe VRP is correctly recognising here `b` can't be more
- Kagamin (8/8) Sep 01 Indeed, works with signed integer
```
char BitsToChar(in uint bit5)
{
const uint b=bit5&0x1f;
return b<10?'0'+b:'a'+(b-10);
}
```
This code can't implicitly convert to char, but a version without
parentheses `'a'+b-10` can. Is this intended or I miss something?
Jun 14
On Sunday, 14 June 2026 at 09:06:13 UTC, Kagamin wrote:
```
char BitsToChar(in uint bit5)
{
const uint b=bit5&0x1f;
return b<10?'0'+b:'a'+(b-10);
}
```
This code can't implicitly convert to char, but a version
without parentheses `'a'+b-10` can. Is this intended or I miss
something?
```
(b - 10)
```
has type `uint` and wraps if `b` < 10.
```
'a' + b - 10
```
is evaluated left to right, `b` is < 32, so `'a' + b` is < 129.
Substract 10 and the expression is < 119. It fits in the range of
char.
But the whole thing is questionable:
- Drop the `const` in `b`'s declaration and the Error shows up
in
the unparenthesized version, too.
- try `+127` and `+128` instead of `-10`.
Jun 14
On Sunday, 14 June 2026 at 09:06:13 UTC, Kagamin wrote:
```
char BitsToChar(in uint bit5)
{
const uint b=bit5&0x1f;
return b<10?'0'+b:'a'+(b-10);
}
```
This code can't implicitly convert to char, but a version
without parentheses `'a'+b-10` can. Is this intended or I miss
something?
I believe VRP is correctly recognising here `b` can't be more
than 31, but is missing that the subexpression won't be evaluated
if it's less than 10.
If I'm right, it's a limitation of value range propagation - Had
I to choose, I'd say it's not exactly a bug, but I leave it to
others to judge that.
Aug 31
Indeed, works with signed integer
```
char BitsToChar(in int bit5)
{
const int b=bit5&0x1f;
return b<10?'0'+b:'a'+(b-10);
}
```
Sep 01









Kagamin <spam here.lot> 