LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2006, 08:24 AM   #16
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22

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.

Last edited by bastl; 06-03-2006 at 09:08 AM.
 
Old 06-03-2006, 08:47 AM   #17
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
int() and long() are not functions as such but are type casts and so they essentially ignore the fractional part.

One observation is that you should check on the return from fesetround() non zero measn it failed.
 
Old 06-03-2006, 08:50 AM   #18
lreason
LQ Newbie
 
Registered: Jun 2006
Posts: 1

Rep: Reputation: 0
Need Help With Password Retrieving!!!!! Please

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 !
 
Old 06-03-2006, 09:24 AM   #19
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HEELLP ~~ Converting an integer minute into time, Rounding off a double ~~ HELLP Mistro116@yahoo.com Programming 5 10-04-2005 11:51 AM
c++: float to double conversion ashirazi Programming 6 11-30-2004 04:14 PM
Float/Double to String? Mega Man X Programming 16 01-03-2004 07:50 PM
Java | C | C++ - Float/Double question Mega Man X Programming 6 01-01-2004 10:14 AM
c: array of poiners(integer or double) jetfreggel Programming 3 12-29-2002 08:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration