Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

Bitwise strangeness

DSP related issues, mathematics, processing and techniques

Re: Bitwise strangeness

Postby MyCo » 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.
User avatar
MyCo
 
Posts: 761
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Bitwise strangeness

Postby Nowhk » Thu Feb 18, 2016 11:38 am

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?
Nowhk
 
Posts: 279
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Postby MyCo » Thu Feb 18, 2016 11:55 am

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
User avatar
MyCo
 
Posts: 761
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Bitwise strangeness

Postby Nowhk » Thu Feb 18, 2016 12:06 pm

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.
Nowhk
 
Posts: 279
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Postby MyCo » Thu Feb 18, 2016 12:18 pm

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
User avatar
MyCo
 
Posts: 761
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Bitwise strangeness

Postby Nowhk » Thu Feb 18, 2016 12:36 pm

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?
Nowhk
 
Posts: 279
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Postby MyCo » Thu Feb 18, 2016 1:41 pm

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
User avatar
MyCo
 
Posts: 761
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Bitwise strangeness

Postby Nowhk » Thu Feb 18, 2016 2:31 pm

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 16700 times

rndint.fsm
(1.57 KiB) Downloaded 402 times


instead, using x - (x % 1) give to me correct result. Am I wrong somethings other?
Nowhk
 
Posts: 279
Joined: Mon Oct 27, 2014 6:45 pm

Re: Bitwise strangeness

Postby MyCo » Thu Feb 18, 2016 2:39 pm

Seems to depend on the CPU:
Attachments
output.PNG
output.PNG (26.54 KiB) Viewed 16700 times
User avatar
MyCo
 
Posts: 761
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Bitwise strangeness

Postby Nowhk » Thu Feb 18, 2016 2:42 pm

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:
Nowhk
 
Posts: 279
Joined: Mon Oct 27, 2014 6:45 pm

PreviousNext

Return to DSP

Who is online

Users browsing this forum: No registered users and 2 guests