Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Rounding to lower whole numbers
Rounding to lower whole numbers
2003-01-14, 11:04 AM #1
This must have a simple answer...

How can I round a number in cog?

i.e. I want to write a bit of code that will round numbers like 1.64 to 1, and 2.78 to 2 and so on.
2003-01-14, 12:31 PM #2
If you use a flex where an int is supposed to be, JK will just spit out the whole number. No need to round down. [http://forums.massassi.net/html/smile.gif]
-Hell Raiser
2003-01-14, 12:42 PM #3
I think you got that backwards...

a flex can have decimal values, an int is an intiger(wholenumber)
I'm just an old man with a skooma problem.
2003-01-14, 12:45 PM #4
Who got what backwards now?
-Hell Raiser
2003-01-14, 1:12 PM #5
If you make a flex then turn it into an int, it won't round, it will just truncate after the decimal. At least, that's how it works in C and C++, I haven't done COG in several months.

If that's the case, does COG have a rounding function? I know in C++ you add .5 then use something like ciel and floor to round up and down. I can't remember if COG has this?
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-01-14, 2:01 PM #6
Like I said, just use a flex like you would an int, and JK will truncate it for you.
-Hell Raiser
2003-01-14, 2:41 PM #7
um no, it's int. Don't use float.

Float = decimal places
Int (short for Intiger) = Whole number

[This message has been edited by Friend14 (edited January 14, 2003).]
Math is infinitely finite, while the universe is finitely infinite. PI = QED
2003-01-14, 3:34 PM #8
Cog scripts do not have the C function floor incorporated into them. And unfortunately I was unable to find the code to any C function that did not use floor that I could translate to cog.

I've been playing with modulus (%) an operator I had not known anything about until today. It seems to return the remainder of a division. (i.e. 7 % 4 = 3, 17 % 5 = 2) I should be able to get it to do what I want with this.

Oh, and the int flex/float argument is irrelevant. JK will automatically change type int into type flex when a decimal value is assigned to it. Or at least that what it seems like to me. And I believe datamaster confirms this...not sure off the top of my head.
2003-01-14, 3:49 PM #9
Yeah, JK will convert the symbol type to any input.


I dont know of any way to easily round off numbers, only truncate them. [http://forums.massassi.net/html/frown.gif]
And when the moment is right, I'm gonna fly a kite.
2003-01-14, 4:55 PM #10
wth? If you round a number down, you're truncating it.

Everyone, reread the first post, he wants to truncate. Yeesh. [http://forums.massassi.net/html/rolleyes.gif]

Just put the fraggin flex whereever you want it, JK doesn't care. Use it to call elements in an array, JK couldn't care less, it'll just round it down IE truncate it.

[This message has been edited by Hell Raiser (edited January 14, 2003).]

Unless of course you want to do a mathmatical operation with it......... [http://forums.massassi.net/html/redface.gif]

[This message has been edited by Hell Raiser (edited January 14, 2003).]
-Hell Raiser
2003-01-15, 3:42 AM #11
I want to do a mathematical operation with it.
2003-01-17, 9:43 AM #12
Your initial post did imply simple truncating of the numbers.

------------------
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
2003-01-17, 11:48 AM #13
Simple way to round floating point numbers: Add 0.5 and then truncate it. And I never knew COG supports the modulo operator...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2003-01-17, 11:54 AM #14
Yes, merely utilise the modulo! That's what it's there for.
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2003-01-17, 12:06 PM #15
This modulo makes me think of a way to encrypt several values into one number...thus making sendtrigger more valueable (especially for shotguns).

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

↑ Up to the top!