# COFFEE/SCRIPT | Can't divide integers?

 06 June 2006 tcastudios Steady now!   ... Sweden COFFEE/SCRIPT | Can't divide integers? Is this correct? I'm using RGB values to set colors. To use the values as vectors I divide each value by 256. However that gives me 0 (Zero). If I add a single decimal, it works fine. So. var r = 116/256; prints 0 and var r = 116/256.0; correctly prints 0.453125 Cheers Lennart __________________ MSA | OSX | xfiles ...Cinema4D Tools share quote
 06 June 2006 unseenthings Where's my hasenfeffer?? portfolio Gregory Dunn 3D Illustrator Unseen Things USA That's not all that uncommon in "untyped" programming language (where you don't specifically identify an item as an integer or float on the front end when you define it) -- without the .0 it doesn't know that you want a float result, so it just gives you the integer result (rounded, I think). So yeah, you're doing it the right way. That's a "feature" __________________ Follow me on Twitter My blog and website share quote
 06 June 2006 tcastudios Steady now!   ... Sweden Thanks. Good to know Concidering I have written a couple of thousends of lines by now, it's strange that I haven't stumbled on it before. Cheers Lennart __________________ MSA | OSX | xfiles ...Cinema4D Tools share quote
 06 June 2006 Darter Positive buoyancy David Wickenden Ballina, Australia As ascent suggests, you can also use float() on one of the variables, e.g. var r = float(116) / 256; This can be useful if the variable is generated elsewhere in the code. Last edited by Darter : 06 June 2006 at 09:53 PM. share quote
 06 June 2006 arctan New Member Warren Young Aztec, USA Originally Posted by ascent: That's not all that uncommon in "untyped" programming language Actually, it goes back to COFFEE's roots in C++, which is very much a typed language: without a decimal point, a numeric literal is considered an integer. An integer divided by another uses an integer divide, with integer result. In mixed expressions, the integers are all promoted to floats, and you get a floating point divide with a float result. It really helps to understand COFFEE if you also know C++, because there are a lot of carryovers like this. share quote
 06 June 2006 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.