ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Yes that's a nice idea, Thank you. - Yes it works. - O.K. in my case it than should work with + 0.0001 because of 5.9999 see above. Yes it works. - now why does ceil() not work? Ups, it works... why not yesterday? I had a restart by turning on my computer this morning. Now I get exactly the results of - graemef, Yesterday, 07:41 PM -. But what was wrong: I did some tests:
Code:
#include <math.h>
#include <fenv.h>
void test( double d )
{
long int x;
fesetround( FE_UPWARD ); // you have FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO on x87 FPUs
x = long( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = floor( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = ceil( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = round( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
}
The result is, that fesetround() has no effect on round() in my case, but on int(), long(), floor(), ceil(). And with fesetround(FE_TONEAREST) it really don't did what it should do with 5.9999. In my case only fesetround(FE_UPWARD) has the behavior I wanted. I think it's the best thing to use round(). I thought round(), int() and long() does the same - no, they don't !
And sorry to all, that my answers came as late, but I did tests and reading in the www.
Now to you -graemef-. No, I only read that int() uses this FPU instruction, I use only int() and long() like in my function test() without inline things, so no assembler code. Only pure gcc code.
I have an improtant question and need help on this, I have recently gotten new PC and I have forgotten my Yahoo messenger password. I do not know how to retrieve it cause I have to have to be able to open the e-mail give orignally with this messenger to retrieve my password, which i get open without the password. I have the ID name just cant get the password. Please help me or direct me to where i can get this. thank you so much, Lreason
Quote:
Originally Posted by bastl
Yes that's a nice idea, Thank you.
- Yes it works.
- O.K. in my case it than should work with + 0.0001 because of 5.9999 see above. Yes it works.
- now why does ceil() not work? Ups, it works... why not yesterday?
I had a restart by turning on my computer this morning.
Now I get exactly the results of - graemef, Yesterday, 07:41 PM -.
But what was wrong:
I did some tests:
Code:
#include <math.h>
#include <fenv.h>
void test( double d )
{
long int x;
fesetround( FE_UPWARD ); // you have FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO on x87 FPUs
x = long( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = floor( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = ceil( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
x = round( d );
KMessageBox::messageBox ( 0, KMessageBox::Information, QString("x = %1\nd = %2").arg(x).arg(d), "Info");
}
The result is, that fesetround() has no effect on round() in my case, but on int(), long(), floor(), ceil(). And with fesetround(FE_TONEAREST) it really don't did what it should do with 5.9999. In my case only fesetround(FE_UPWARD) has the behavior I wanted.
I think it's the best thing to use round().
I thought round(), int() and long() does the same - no, they don't !
I observed now the function fesetround(), it gives back always 0.
And the behavior of int() and long() changes on executing fesetround() with different values.
But it seems that only the binary deviation of the floating point numbers are handled with.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.