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
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Bitwise strangeness
Re: Bitwise strangeness
Re: Bitwise strangeness
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);
Re: Bitwise strangeness
Code: Select all
y = rndint(x-0.49999991);in the 3.0.9b1 you can use "int" as it works there and is also a lot faster
Re: Bitwise strangeness
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)
Re: Bitwise strangeness
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.
Re: Bitwise strangeness
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
Re: Bitwise strangeness
Code: Select all
streamout o1;
streamout o2;
float x = 1;
o1 = rndint(x - 0.49999991);
o2 = rndint(x - 0.5);
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);
instead, using x - (x % 1) give to me correct result. Am I wrong somethings other?
Re: Bitwise strangeness
- Attachments
-
- output.PNG (26.54 KiB) Viewed 33159 times
Re: Bitwise strangeness
MyCo wrote:Seems to depend on the CPU:
So I'll keep (until I'll upgrade to last version, where int() should floor correctly, I hope) x - (x % 1)