LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-16-2004, 08:35 AM   #1
registering
Member
 
Registered: Jun 2003
Location: Florida, USA
Distribution: Drake 10.1 Download
Posts: 182

Rep: Reputation: 30
FLT_MAX and FLT_MIN confusion...


Hi all,
I'm trying to figure out the minimum and maximum values for a float my system can handle. However when I execute this code:

Code:
using namespace std;

#include <iostream>
#include <cfloat>   //calls /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include/float.h
#include <iomanip>

int main(int argc, char *argv[], char *envp[])
{
   float  max = FLT_MAX;  //should be 3.40282347e+38F
   float  min = FLT_MIN;  //should be 1.17549435e-38F (not negative??)
   
   cout << "\nFLT_MAX:          " << fixed << max; 
   cout << "\nFLT_MIN:          " << fixed << min;    
   
   max -= 125.0;
   cout << "\nMAX MINUS 125:    " << fixed << max;
   
   min += 125.0;
   cout << "\nMIN PLUS 125:     " << fixed << min; 
   
   max *= -1; 
   cout << "\nMAX NEGATIVE:    " << fixed << max;
   min *= -1;
   cout << "\nMIN NEGATIVE:    " << fixed << min;
   
   cout << endl;
   
   return (0);
   
} //end main(...)

I get this output:


FLT_MAX: 340282346638528859811704183484516925440.000000
FLT_MIN: 0.000000
MAX MINUS 125: 340282346638528859811704183484516925440.000000
MIN PLUS 125: 125.000000
MAX NEGATIVE: -340282346638528859811704183484516925440.000000
MIN NEGATIVE: -125.000000


Why is FLT_MIN zero? Why can't max be decreased? Thanks for any pointers.
 
Old 10-18-2006, 03:05 PM   #2
roelofs
LQ Newbie
 
Registered: Dec 2005
Distribution: Slackware
Posts: 8

Rep: Reputation: 0
You've probably figured this out in the intervening two and a half years, but the problem with the minima is your use of the "fixed" formatting keyword. That limits the number of (fraction) decimal places to six, and obviously it's not going to show much when you need 37 zeros before you start printing "interesting" numbers.

Adding the following line at the top...

Code:
   cout << "\nFLT_MIN:          " << min;
...prints the following non-trivial value:

Code:
   FLT_MIN:          1.17549e-38
In addition, it appears that "fixed" is sticky, much like "hex" (IIRC); that is, it stays in effect until you cancel it. I can't find the URL to my favorite reference for this stuff (somewhere on the GNU/GCC site), but that's what I recall.
 
  


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
a little confusion..... b0nd Linux - Newbie 1 02-17-2005 06:45 AM
Swaret confusion Vindane Slackware 31 06-29-2004 11:01 AM
partitioning confusion new2server Linux - General 3 03-28-2004 07:36 PM
WM Confusion phoeniXflame Slackware 3 02-16-2003 05:19 AM
Some confusion about RH 7.3 psyklops Linux - Distributions 2 05-08-2002 03:08 PM

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

All times are GMT -5. The time now is 07:48 PM.

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