• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Double overflow

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to create a Profiler. One of the thing sit uses is time elapsed. Go I've been using Java's getNano time method. However, I"m getting floating point overflow. What can I do about it ?

This is the value I'm getting for time_frame_ratio. It should be positive.
-1.8934460908370767E-5

timeSpent is  15957017

frametime is overflowing too. its value is somewhere around -842750003669. it's a long

 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you calculating "frametime" ?
 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
long frameTime = endFrame - beginFrame;



 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any variable named "frametime" in the code you posted.
 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never write == false or == true, which are both bad style and error‑prone.
It is not obvious how you are getting the frametime variable from line 6 into the rest of the code. It is also not obvious how you are getting values from that infinite loop into the rest of the code. What is more, if you have that infinite loop, are you setting the start time in line 4 after you have set the finishing time in line 22?
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind that doubles don't overflow. If you have a double variable with a positive finite starting value and you keep adding to it or multiplying it with a finite positive amount, eventually it will reach Double.MAX_VALUE, and stay there. If the value you add or multiply it with is small enough, it won't even ever reach Double.MAX_VALUE, instead settling at a lesser value.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ted Gress wrote:
I'm trying to create a Profiler. One of the thing sit uses is time elapsed. Go I've been using Java's getNano time method. However, I"m getting floating point overflow. What can I do about it ?



The nano timer should return the number of nanoseconds from an arbitrary point in time. Implementation wise, it should be using the processor's clock tick counter, so the arbitrary point should be the point of when the processor is turned on. Due to precision issues, it may not be exact to the nanosecond (as clock ticks doesn't occur as frequent as nanoseconds), but the range should be large enough to not have overflow for large periods.

Regardless, although I haven't done the math, I think that the JavaDoc calculates that the overflow is around 292 years. So, you need to have your processor running for that long before you get an overflow -- or arguably, half of that, if you are not taking differences.

Anyway, something tells me that this may be related to a mathematical error, and not an overflow of the nano second timer.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Keep in mind that doubles don't overflow. If you have a double variable with a positive finite starting value and you keep adding to it or multiplying it with a finite positive amount, eventually it will reach Double.MAX_VALUE, and stay there. If the value you add or multiply it with is small enough, it won't even ever reach Double.MAX_VALUE, instead settling at a lesser value.



Doubles do not overflow, but the long type (which is returned by the timer) do. So, it could be an overflow somewhere prior to the value being converted to a double. And as mentioned, since it is unlikely to be the timer, it is likely the math after the timer value is returned.

Henry
 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Never write == false or == true, which are both bad style and error‑prone.
It is not obvious how you are getting the frametime variable from line 6 into the rest of the code. It is also not obvious how you are getting values from that infinite loop into the rest of the code. What is more, if you have that infinite loop, are you setting the start time in line 4 after you have set the finishing time in line 22?




Ok. I'lll try to clear this up.

The infinite loop sets a static value in CProfiler:





Main Game Loop:




So the maingame's loop sets the beginFrame and endFrame directly (should be using getters and setters, i know)  in CProfiler.


The method Percentages() in CProfiler calculates the statistics for the profiler. Here the frameTime is calculated. long frameTime = endFrame - startFrame;





I think that the problem is the division here:




Is the issue is at time_frame_ratio, it is doing floating point division. time_Frame_ratio is the only value that is coming back negative.


 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ted Gress wrote:
Is the issue is at time_frame_ratio, it is doing floating point division. time_Frame_ratio is the only value that is coming back negative.



The issue is when the timestamps are taken, and when the timestamps are used. Basically, the begin frame is taken at the top of the loop, while the end frame is taken at the bottom of the loop.

The ratio, however, is taken in the percentage() method, which is called from the middle of the loop. So, you are using the begin frame from the current iteration of the loop, but not the end frame value. The end frame was set with the previous iteration, as the current iteration hasn't reached it yet in the code path.  This means that the end frame was taken before the begin frame. Or in other words, the difference in time will be negative, as the end time is before the begin time.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic