symmetric signed types
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Sat Jan 25 09:15:54 PST 2014
On Friday, 24 January 2014 at 22:59:08 UTC, Andrei Alexandrescu
wrote:
> integral expressions are handled. For example I found it
> ridiculous that unary "-" for uint returns uint. Walter talked
Fortunately most CPUS have ones-complement so the result is
correct if you only use one unsigned type.
-$01 == (~$01)+1
-$01 == $ff
$ff+$03 == ($102)&($ff)
$ff+$03 == $02
This is useful for interpolating oscillators (going from 1 to 0,
or 0 to 1)
ulong phase, delta;
...
phase += delta;
sample1 = wavetable[phase>>16];
sample2 = wavetable[(phase>>16) + 1];
return interpolate16bit(sample1,sample2,phase&0xffff);
It is the automatic promoting of unsigned types that is a
C-language bug IMHO.
More information about the Digitalmars-d
mailing list