Re: Bitwise strangeness
Posted: Thu Feb 18, 2016 11:34 am
If you can avoid it, do it. It's basically the slowest math operator... Only some functions (eg. log10, exp, pow) are slower.
DSP Robotics and FlowStone Graphical Programming Software Support and Forums
https://dsprobotics.com/support/
I'm only using it to "flooring" a value right now:MyCo wrote:If you can avoid it, do it. It's basically the slowest math operator... Only some functions (eg. log10, exp, pow) are slower.
Code: Select all
pos = index-(index%1);
Code: Select all
pos = int(index);
Code: Select all
y = rndint(x-0.49999991);I see (I always think 0.5 was the correct scaling). But why:MyCo wrote:for old versions you can usefor truncation, it works as long as x >=0Code: Select all
y = rndint(x-0.49999991);
Code: Select all
rndint(0-0.49999991)
0.5 would round integer numbers down too, eg. 2 would round down to 1Nowhk wrote:I see (I always think 0.5 was the correct scaling)
Yeah, floating point system has two zeros, so the sign of the input is carried through the operationNowhk wrote:return -0 and not 0? On Some "display" value that's weird.
Uhm...MyCo wrote:0.5 would round integer numbers down too, eg. 2 would round down to 1
Code: Select all
int(1.5);
rndint(1.5)
And what if I want 0 instead of -0 with this technique?MyCo wrote:Yeah, floating point system has two zeros, so the sign of the input is carried through the operation
Code: Select all
streamout o1;
streamout o2;
float x = 1;
o1 = rndint(x - 0.49999991);
o2 = rndint(x - 0.5);
MyCo wrote:That's not what I meant, try this to see the difference:Code: Select all
streamout o1; streamout o2; float x = 1; o1 = rndint(x - 0.49999991); o2 = rndint(x - 0.5);
MyCo wrote:Seems to depend on the CPU: