473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

unmanaged float / double question

Hi,

i have a simple question that has bothered me for some time now.

if i have a function foo( double a)
and i do something like

float b = 2.0;
foo(b);

* can i safely assume that the compiler will convert b to a double?

and if i do foo(20) //notice that i coded an integer number

* will vc do the correct conversion?

i ask this because recently i had to work with an archaic HP-UX compiler
that tried to use a binary represtation of the integer '20' as a floating
point. i was wondering if vc is smarter. if it is not, where should i look
for documentation about this?
i used to think that this was a non-issue, but apparently this is not always
true.

* and while i am on that subject, is it correct that there is no way for
format specifiers to work with double precision floats?

kind regards,
Bruno.
Nov 17 '05 #1
1 1609
Hi,

C++ does this for you - you'll get a warning about type conversion from the
double -> float conversion in
float b = 2.0
and the integer -> double conversion should go OK without any warnings.
However, as a rule, it's best not to rely on it - you'd be better checking
your types yourself since type conversion can lead to trouble (most
noticeably with unsigned / signed conversion). There's a compiler option to
turn off implicit conversion (treat it as an error).

HTH,

Steve

"Bruno van Dooren" <mi******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

i have a simple question that has bothered me for some time now.

if i have a function foo( double a)
and i do something like

float b = 2.0;
foo(b);

* can i safely assume that the compiler will convert b to a double?

and if i do foo(20) //notice that i coded an integer number

* will vc do the correct conversion?

i ask this because recently i had to work with an archaic HP-UX compiler
that tried to use a binary represtation of the integer '20' as a floating
point. i was wondering if vc is smarter. if it is not, where should i look
for documentation about this?
i used to think that this was a non-issue, but apparently this is not always true.

* and while i am on that subject, is it correct that there is no way for
format specifiers to work with double precision floats?

kind regards,
Bruno.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Christian Christmann | last post by:
Hi, just a general question. Which data type is more precise for large values: float or double? Thank you. Chris
2
by: JohnO | last post by:
I am new to CppNet How can I pass a double or float value to Unmanaged function from Managed CppNet Program. I can pass an integer with no problem but when I try it with double or float I get the...
1
by: Amir Kolsky via .NET 247 | last post by:
Hello all, this is my first time here so please be gentle :-) We have a VC++ program that does many floating point (float, notdouble) and we are seeing that the results of runs under VC6 andCV7...
2
by: The unProfessional | last post by:
Any know how to convert a managed array to an unmanaged array (ptr)? // Managed float f = new float ; // Unmanaged unsafe { float *pArray = f; // No good
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
8
by: abdul_n_khan | last post by:
Hello, I have a basic question related to datatypes. I am trying to read a value using Microsoft's ADO recordset from a field (lets call it 'Price') with datatype decimal(19,6) => 19 = Precision,...
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
22
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never...
0
by: MottetCCSF | last post by:
I have created 2 structures in my C# code : public class RollInformationCSharp { public double rollDiameter; public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.