- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, (Intel 10.1, VS2005, min target build Core2 microarch SSE3)
I have a very tight loop decrementing a double that looks like:
double time, dt;
for (int t=N-1; t>=0; t--)
...
time -= dt;
with dt variable, depending on t, but such that at the end of the loop (t==0), time shouldbe "exactly" 0.0.. Due naturally to floating calculations, time sometimes becomes negative-1e-170 or so...
1) I believe there is some flag to "round down" to 0 if a double is small "enough"...
2) Otherwise, i could do a test to see if time is negative....
time -= dt;
if (time<0.0) time=0.0;
Is this fast enough? Or is there some other function from mathimf.h to do it faster? ( i mean that gets assembled to some more appropriate instruction )....
regards,
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In such a situation, you may get better results from something similar to
time = t * dt;
Possibly faster might be to keep a double copy of t to use in this calculation.
Setting abrupt underflow (e.g. by setting /Qftz in your compilation) might avoid accidental generation of such small non-zero numbers.
When you use SSE2 or SSE3, your
if (time<0.0) time=0.0;
should compile to fast code (maxsd instruction, no branching).
time = t * dt;
Possibly faster might be to keep a double copy of t to use in this calculation.
Setting abrupt underflow (e.g. by setting /Qftz in your compilation) might avoid accidental generation of such small non-zero numbers.
When you use SSE2 or SSE3, your
if (time<0.0) time=0.0;
should compile to fast code (maxsd instruction, no branching).

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page