Bitwise strangeness

DSP related issues, mathematics, processing and techniques
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Bitwise strangeness

Post by MyCo »

If you can avoid it, do it. It's basically the slowest math operator... Only some functions (eg. log10, exp, pow) are slower.
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Post by Nowhk »

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.

I'm only using it to "flooring" a value right now:

Code: Select all

pos = index-(index%1);

Will the new compiler have this function? If I don't remember bad, the new int() will do it:

Code: Select all

pos = int(index);

right?
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Bitwise strangeness

Post by MyCo »

for old versions you can use

Code: Select all

y = rndint(x-0.49999991);

for truncation, it works as long as x >=0

in the 3.0.9b1 you can use "int" as it works there and is also a lot faster
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Post by Nowhk »

MyCo wrote:for old versions you can use

Code: Select all

y = rndint(x-0.49999991);

for truncation, it works as long as x >=0

I see (I always think 0.5 was the correct scaling). But why:

Code: Select all

rndint(0-0.49999991)

return -0 and not 0? On Some "display" value that's weird.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Bitwise strangeness

Post by MyCo »

Nowhk wrote:I see (I always think 0.5 was the correct scaling)


0.5 would round integer numbers down too, eg. 2 would round down to 1

Nowhk wrote:return -0 and not 0? On Some "display" value that's weird.


Yeah, floating point system has two zeros, so the sign of the input is carried through the operation
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Post by Nowhk »

MyCo wrote:0.5 would round integer numbers down too, eg. 2 would round down to 1

Uhm...

Code: Select all

int(1.5);
rndint(1.5)

(which is 2-0.5) both rounds to 2 (not 1).

MyCo wrote:Yeah, floating point system has two zeros, so the sign of the input is carried through the operation

And what if I want 0 instead of -0 with this technique?
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Bitwise strangeness

Post by MyCo »

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);


0 == -0 in most cases so just ignore it. When you want to display it at some point using green/ruby you can just compare it like: if x==0 then show 0
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Post by Nowhk »

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);

:shock: Both output the same here. x=1 output 0 (which is "wrong";), while x=2 output 2:

Immagine_2.png
Immagine_2.png (23.34 KiB) Viewed 31902 times

rndint.fsm
(1.57 KiB) Downloaded 1371 times


instead, using x - (x % 1) give to me correct result. Am I wrong somethings other?
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Bitwise strangeness

Post by MyCo »

Seems to depend on the CPU:
Attachments
output.PNG
output.PNG (26.54 KiB) Viewed 31902 times
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Post by Nowhk »

MyCo wrote:Seems to depend on the CPU:

:o :shock: Yes, but I can't trust in different CPU 8-)
So I'll keep (until I'll upgrade to last version, where int() should floor correctly, I hope) x - (x % 1) :twisted:
Post Reply