Page 1 of 2
how to get a fraction in blue
Posted: Sun Sep 15, 2013 4:43 pm
by tester
How to get (simplest way) a factional part in blue?
Like 4.543 -> 0.543
rndint(x) works differently than green int philosophy.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 4:56 pm
by strangeChild
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 4:58 pm
by tester
Nope. Check the numbers with fraction above #.5, like 3.8
Code int rounds up or down. Green integer splits the integer and fractional part.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 4:59 pm
by strangeChild
Yeah... posted without checking (or thinking!)... Sorry.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 5:07 pm
by strangeChild
out = in - rndint(in-0.5);
But only with positive values
For negative and positive values this looks like it works:
Code: Select all
streamin in;
streamout out;
float adj;
adj = 0.5 - (1 & (in<0));
out = in - rndint(in-adj);
(the assembly people can give you a proper solution)
EDIT - final - DOESN'T WORK WITH FLOATS THAT ARE ALREADY INTEGERS... I'll shut up now.

Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 5:16 pm
by tester
Need for both - positive and negative values.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 5:20 pm
by strangeChild
Was editing last post when you replied... but as I said the assembly guys will give you something much better but this does seem to work.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 5:20 pm
by tester
Yeah, just came to similar thing, but I was wondering - if there is a simpler, "one operation" way.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 7:59 pm
by MyCo
This doesn't look simpler, but actually it's a lot faster.
Re: how to get a fraction in blue
Posted: Sun Sep 15, 2013 9:02 pm
by strangeChild
for something that looks simple...
I missed that there's a modulus divide.
