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
Topic
Rimmer
Sweden
25 Posts
Posted - 11/15/2003 : 05:15:05 AM
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
Hi Mick,
Try this...
scalex = (double) x1 / x2;
Mike Buess
Origin WebRing
Member
Rimmer
Sweden
25 Posts
Posted - 11/15/2003 : 1:16:11 PM
Thanks that worked
Seems strange to have to cast in such a simple case
Mick
cpyang
USA
1406 Posts
Posted - 11/15/2003 : 4:35:01 PM
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
Topic
New Topic
Reply to Topic
Printer Friendly
Jump To:
Select Forum
Origin Forum
Origin Forum
Origin Viewer Forum
Origin Forum for Programming
Forum for Python
LabTalk Forum
Forum for Origin C
Forum for Automation Server/COM and LabVIEW
Origin中文论坛
Origin 中文论坛 (Chinese Origin Forum)
Japanese Origin Forum
Origin日本語フォーラム (Japanese Origin Forum)
Origin on Linux
The Origin on Linux Forum
Private Forums
Distributor Forum
--------------------
Home
Active Topics
Frequently Asked Questions
Member Information
Search Page
The Origin Forum
© 2020 Originlab Corporation
Snitz Forums 2000