modulus on a float value?

cirthix

Diamond Member
Aug 28, 2004
3,616
1
76
is there a way to do this? google calculator can handle a float%float calculation, so can c?

if you have a better way to round to the nearest half than to do the following, please tell.

n -n%1 + round(n%1)

round is a function that just rounds to the nearest integer
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
How about ((float)((int)((2*n) + .5)) / 2) Or something to that effect

In English - multiply by 2, add .5, cast to int to chop off all decimals. Cast back to float and divide by 2.
 
Sep 29, 2004
18,656
67
91
Same as the integer operation?

mx+b=c

You know x and c. Jsut solve for m and b.

That's all there is to it.
 

cirthix

Diamond Member
Aug 28, 2004
3,616
1
76
Originally posted by: IHateMyJob2004
Originally posted by: cirthix
thank you mugs, you gave me the idea for this
int(n) + (round(n-int(n)))/2

My idea is better.


haha, you dont know what the hell you are talking about. thanks for trying to help though :)