Page 2 of 3

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 11:34 am
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.

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 11:38 am
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?

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 11:55 am
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

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 12:06 pm
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.

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 12:18 pm
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

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 12:36 pm
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?

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 1:41 pm
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

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 2:31 pm
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 28597 times

rndint.fsm
(1.57 KiB) Downloaded 1147 times


instead, using x - (x % 1) give to me correct result. Am I wrong somethings other?

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 2:39 pm
by MyCo
Seems to depend on the CPU:

Re: Bitwise strangeness

PostPosted: Thu Feb 18, 2016 2:42 pm
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: