The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Divide
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Rimmer

Sweden
25 Posts

Posted - 11/15/2003 :  05:15:05 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Sorry for the extremely basic question, but I have two ints x1 and x2 and a double scalex. However when I write

scalex = x1 / x2

the result in scalex is always an integer and not the double that I require.

Why do I have this behaviour?

Thanks

Mick

Mike Buess

USA
3037 Posts

Posted - 11/15/2003 :  09:11:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mick,

Try this...

scalex = (double) x1 / x2;

Mike Buess
Origin WebRing Member
Go to Top of Page

Rimmer

Sweden
25 Posts

Posted - 11/15/2003 :  1:16:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks that worked

Seems strange to have to cast in such a simple case

Mick
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/15/2003 :  4:35:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That is how it is in C/C++, when doing arithmetics between integers, then the result is also must be an integer, so must cast at least one value into double so that the arithmetics will result into double.

CP


Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000