display "double" without loss of data

Posted on 2003-12-12
Last Modified: 2010-04-06
     Iam new to graphics programming.
   Iam involved in some mathematical formulation and endup with "double data type".
while trying to display the after proper scaling, I receive a warning " possible loss of data".

please help

best regards

Question by:cbodapati
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4

Expert Comment

ID: 9930624
OK, note that the error says "possible" that means it may not be loosing any data.
The second thing to note is that this is a compiler warning message, which enerally implies that you are trying to covert some sort of data type (doubles in this case) to another data type (possibly integers).
What are the two types you are converting between? Also, what language are you using and what is development program you are using?

Note that if you are using those values to plot pixel locations etc then it is not possible to put a pixel at location 2.5 for example, the pixel will have to be at either screen location 2, or 3.

Author Comment

ID: 9933345
hello shamstar
    Iam coding in VC++,using winAPI, audio recording program.
to display the DFT reults.
    now Iam laded in a very strange problem.
       in my program iam not able  to initialise all the buffers to zero.
       when I check randomly the value is not a zero.
 I included math.h, even the poblem persists.
    what should I do.


Expert Comment

ID: 9944757
Hummm... strange problem.
But quite likely to have a simple solution.  Are you setting the data to zero through pointers? In which case you should verify that the pointers point to the correct location in memory.
You should also make sure that the code where you read the values back from the buffer is correct.
If the values are still zero, are you sure you have initialised the buffer correctly.
Lastly, check to make sure that the values in the buffer are not changed somewhere else in the code after you have initialised them.

If you are familiar on using the VC++ debugger then you should ideally use this to check the data held in the memory locations of the buffer.  You should also set the program to break when a value in the buffer is changed, that way you can be sure that some other bit of code isn’t changing the buffer values after you have initialised them.
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button


Author Comment

ID: 9947470
hello shamstar
       now Iam solved with the initialisation problem.
   how to display the double datatype without loss of data.
   am I only the person facing the problem or I think this problem is quite common coz, many involve in maths and endup in double data(dealing with sin and cos).how do they manage.

please make clear

best regards

Accepted Solution

shamstar earned 125 total points
ID: 9948413
Ok, as I mentioned before, when it comes to doing graphics, the smallest unit you can use to draw something is a pixel.  Therefore it clearly isn’t possible to draw something at 10.41 pixels in from the screen, however you can draw it at either pixel 10 or pixel 11.
There are a number of different steps you can take when drawing things to screen.

The first, and simplest way is that you simple ignore the part after the decimal point, to if you value is 52.56673 you simply draw to pixel 52.

Sometimes the above method is fine to use, but in other situations, more precision is required.
In this case what you can do is to add the numbers after a decimal point together until they are equal to or great than 1, then this can be added to the rest of the value... so for example:
  if I have calculate the position of a car with a variable: real TheCar, and i want to
  plot the car position to the screen over a number of frames, then I can do this: this every frame or while output is needed:
       TheCar = DoCalculation();
       if ( (TheCar - (int)TheCar) <> 0 )
                         TempStorage = TempStorage + ( TheCar - (int)TheCar);

       if ( TempStorage => 1 )
                         TheCar = TheCar + 1;
                         TempStorage = TempStorage -1;

That’s just some quick code that might help you to see how you can ignore the fractional part of the number until it becomes a size which you can draw to the screen.  In essence what it does is: say the value of TheCar is always 2.3 and TempStorage starts as 0.
Then in the value of those values are shown below in their successive iterations:
Note the value of the car is truncated to a decimal number since only those can be plotted on a screen.

  Iteration     TheCar       TempStorage
       1               2                   0.3
       1               2                   0.6
       1               2                   0.9
       1               3                   0.2       <---- TheCar value has been increased
       1               2                   0.5

Hopefully I’ve explained that well enough for you to understand the concept.

The third and final thing you can do is to simply use a function to round the double precision number either up or down based on its value, they may be the easiest-best solution in most cases.

Maybe Ive got things wrong here and you actually want to know how to display the text value of the double precision number???

Author Comment

ID: 9949327
 hello shamstar
     i want to display only the int part.(no decimal part). but is it sure that there is no loss of data.(the value is well below the range of the max int value).I know the pixel position take only the integral values.  

thanking you
best regards


Expert Comment

ID: 9949951
If you only want to display the integer part then you arnt loosing any of the data that you want to keep.  The compiler only give you that warning just to inform you of whats going on.  The method you're using the probally the best way to display only the integer part of the number so theres nothing to worry about, you can simply ignore those compiler warning.

Goodluck with your program!

Author Comment

ID: 9962468
 hello Mr shamstar
    thank q,  I'll come back to you if any problem arises.
mean while

    when iam recording, the recorded sound is being heard from the speakers . can I get rid of this feature.
   I want only recording (without playback).
 Iam using
   windows 98-VC++,WinAPI.
 please help me

best regards

Expert Comment

ID: 9963226
Yes, you can turn it off... this is most likely due to an option set somewhere in your control panels.
The name of the command you need to look for varies from software to software so I couldnt tell you what to look for exactly... but often its known as "Playthrough".
Genreally, you should look around in the Sounds and Multimedia control panel (try looking in some of the advanced settings).

If you cant find it there, then the recording program may well have an option to turn off the playback as well.  What program are you using to record sounds?

[Note that this thread may no longer allow us to post (since it has been closed - not sure), but if it does, then just create a new one somewhere with my name in it and I'll reply there.]

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question