Solved

display "double" without loss of data

Posted on 2003-12-12
9
233 Views
Last Modified: 2010-04-06
 hello  
     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
srikanth  

0
Comment
Question by:cbodapati
  • 5
  • 4
9 Comments
 
LVL 8

Expert Comment

by:shamstar
Comment Utility
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.
0
 

Author Comment

by:cbodapati
Comment Utility
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.


regards
srikanth
 
0
 
LVL 8

Expert Comment

by:shamstar
Comment Utility
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.
0
 

Author Comment

by:cbodapati
Comment Utility
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
srikanth
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 8

Accepted Solution

by:
shamstar earned 125 total points
Comment Utility
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:

        ...do 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???
0
 

Author Comment

by:cbodapati
Comment Utility
 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
srikanth

0
 
LVL 8

Expert Comment

by:shamstar
Comment Utility
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!
0
 

Author Comment

by:cbodapati
Comment Utility
 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
srikanth
0
 
LVL 8

Expert Comment

by:shamstar
Comment Utility
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.]
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now