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
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Bitwise strangeness
23 posts
• Page 2 of 3 • 1, 2, 3
Re: Bitwise strangeness
If you can avoid it, do it. It's basically the slowest math operator... Only some functions (eg. log10, exp, pow) are slower.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Bitwise strangeness
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: 275
- Joined: Mon Oct 27, 2014 6:45 pm
Re: Bitwise strangeness
for old versions you can use
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
- 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
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Bitwise strangeness
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: 275
- Joined: Mon Oct 27, 2014 6:45 pm
Re: Bitwise strangeness
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
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Bitwise strangeness
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: 275
- Joined: Mon Oct 27, 2014 6:45 pm
Re: Bitwise strangeness
That's not what I meant, try this to see the difference:
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
- 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
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Bitwise strangeness
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);
Both output the same here. x=1 output 0 (which is "wrong";), while x=2 output 2:
instead, using x - (x % 1) give to me correct result. Am I wrong somethings other?
- Nowhk
- Posts: 275
- Joined: Mon Oct 27, 2014 6:45 pm
Re: Bitwise strangeness
Seems to depend on the CPU:
- Attachments
-
- output.PNG (26.54 KiB) Viewed 28427 times
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Bitwise strangeness
MyCo wrote:Seems to depend on the CPU:
Yes, but I can't trust in different CPU
So I'll keep (until I'll upgrade to last version, where int() should floor correctly, I hope) x - (x % 1)
- Nowhk
- Posts: 275
- Joined: Mon Oct 27, 2014 6:45 pm
23 posts
• Page 2 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 16 guests