473,395 Members | 1,404 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.

The default double values get truncated

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...

--
Vänligen Kerstin Viltersten
(The Cool Giraffe)
May 25 '07 #1
2 1703
On May 25, 12:49 am, "The Cool Giraffe" <giraf...@viltersten.com>
wrote:
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.
May 25 '07 #2
The Cool Giraffe wrote:
>
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)
May 25 '07 #3

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

Similar topics

6
by: Simon | last post by:
Hi all I am writing a small app that uses real numbers all over the place for calculations. But when it comes to displaying values it is better to only display an it, (especially when it...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
0
by: bunty.gopal | last post by:
I am trying to use the PreparedStatement's addBatch to load data in an ETL-like process into a table. There is a single prepared statement. The parameters are set on it and prepStmt.addBatch() is...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
1
by: bunty.gopal | last post by:
This is the solution to the issue in the subject, question itself was posted in a previous thread long back. Use the latest DB2 db2cc.jar fixpack on the client, or add "deferPrepares=false" to...
5
by: John Doe | last post by:
I have a not-so-large double in the range 1-1000, but with fractional part. I only do ++my_double to increment it, however sometimes it happens that after incrementing int(old_double) ==...
248
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
8
by: Peter Ramsebner | last post by:
Is there an explication why it's executed the then path? Dim a As Double = 10 Dim b As Double = 3 Dim c As Double = 3 Dim x As Double Dim y As Double = 10 x = a / b x *= c If x = y Then
6
by: Nathan Sokalski | last post by:
I know that Single and Double can only store values that can be stored as x/2^y, such as 0.5 and 0.125. But when they attempt to store values such as 0.1 or 0.2 whose exact value cannot be stored,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.