The default double values get truncated

T

The Cool Giraffe

I've designed a method in the class called Blopp.

class Blopp { void foo (int a = 3, double b = 3.6) {} } ;

The problem is only that when i call the method, the
value of b seems to be truncated, if one believes the
(un?) helpful IDE that pops out an info-note. On it,
the value has been clearly lowered to 3.0!

I went debugger on it and it seems that the actual
value indeed is 3.6, as supposed to. However, when
the helping info-notes give one strange suggestions,
it often implies that _something_ is wrong.

What could be a reason for this kind of behavior,
regarding the pure "C++ code"-wise. Should or need
i to use an "d" after the value to explicitly indicate
the double-ness of it? I didn't expect it to be so,
but then again, i didn't expect the truncation either...
 
S

Salt_Peter

I've designed a method in the class called Blopp.

class Blopp { void foo (int a = 3, double b = 3.6) {} } ;

sorry to break the peace and quiet, but Blopp::foo(...) is private.
So please explain how and where you are calling that member function
(ie: show something that compiles).
The problem is only that when i call the method, the
value of b seems to be truncated, if one believes the
(un?) helpful IDE that pops out an info-note. On it,
the value has been clearly lowered to 3.0!

I went debugger on it and it seems that the actual
value indeed is 3.6, as supposed to. However, when
the helping info-notes give one strange suggestions,
it often implies that _something_ is wrong.

What could be a reason for this kind of behavior,
regarding the pure "C++ code"-wise. Should or need
i to use an "d" after the value to explicitly indicate
the double-ness of it? I didn't expect it to be so,
but then again, i didn't expect the truncation either...

That double won't get truncated, it might however get converted into
an integer depending on what you do with it. Again, show code that
compiles, otherwise we can spend the next 2 decades disscussing all
the possibilities.
 
P

Pete Becker

The said:
I went debugger on it and it seems that the actual
value indeed is 3.6, as supposed to. However, when
the helping info-notes give one strange suggestions,
it often implies that _something_ is wrong.

What could be a reason for this kind of behavior,
regarding the pure "C++ code"-wise. Should or need
i to use an "d" after the value to explicitly indicate
the double-ness of it? I didn't expect it to be so,
but then again, i didn't expect the truncation either...

The type of 3.6 is double.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top