how to get a fraction in blue

For general discussion related FlowStone
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

how to get a fraction in blue

Post 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.
Attachments
splitter.fsm
(1.39 KiB) Downloaded 978 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: how to get a fraction in blue

Post by strangeChild »

Code: Select all

out = in-rndint(in);
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: how to get a fraction in blue

Post 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.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: how to get a fraction in blue

Post by strangeChild »

Yeah... posted without checking (or thinking!)... Sorry.
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: how to get a fraction in blue

Post 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. :oops:
Last edited by strangeChild on Sun Sep 15, 2013 6:00 pm, edited 3 times in total.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: how to get a fraction in blue

Post by tester »

Need for both - positive and negative values.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: how to get a fraction in blue

Post 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.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: how to get a fraction in blue

Post by tester »

Yeah, just came to similar thing, but I was wondering - if there is a simpler, "one operation" way.
Attachments
splitter1.fsm
(1.85 KiB) Downloaded 955 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: how to get a fraction in blue

Post by MyCo »

This doesn't look simpler, but actually it's a lot faster.
Attachments
Stream fraction (MyCo).fsm
(1.85 KiB) Downloaded 992 times
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: how to get a fraction in blue

Post by strangeChild »

for something that looks simple...

Code: Select all

out = in%1;

I missed that there's a modulus divide. :lol:
Post Reply