Google Answers Logo
View Question
 
Q: Calculating smallest positive float / double ( No Answer,   4 Comments )
Question  
Subject: Calculating smallest positive float / double
Category: Computers
Asked by: shaneb2000-ga
List Price: $2.00
Posted: 01 Jun 2004 08:35 PDT
Expires: 01 Jul 2004 08:35 PDT
Question ID: 354739
I am interested in an algorithm to calculate the smallest possible
positive float and double.

Clarification of Question by shaneb2000-ga on 01 Jun 2004 12:38 PDT
I am looking for an algorithm in C++ to check the smallest positive
float point number

Thanks
Answer  
There is no answer at this time.

Comments  
Subject: Re: Calculating smallest positive float / double
From: graememcrae-ga on 01 Jun 2004 11:47 PDT
 
The smallest possible floating point number, and the smallest possible
double-precision floating point number, depend on a number of factors.

A floating point number (both floats and doubles are floating point
numbers) consists of an exponent and a mantissa.  Together, the number
of bits in the exponent plus the number of bits in the mantissa
comprise the total number of bits in the floating point number.  The
number of bits in the exponent determines how big (or how small, which
is germane to your question) it can be.

If the exponent is 8 bits, for example, then it can range from -128 to
+127.  The mantissa is taken to have an imaginary decimal point (more
correctly termed "binary point") before the first digit.  It is
considered "normalized" when the first digit is 1.  So, if the
exponent is 8 bits, regardless of the size of the mantissa, the
smallest normalized floating point number is 2^-65, or about
2.71051E-20.

Different computers (different CPU chips) have slightly different
conventions for interpreting the exponent, even if the exponents are
the same size.  The example I gave is typically called the "excess-64"
convention.  Other conventions, such as excess-63, or excess-62 would
also be possible.  Also, different CPU chips might have different ways
to interpret the mantissa.  The imaginary binary point need not be
before the first bit, for example.

So to know the smallest possible float, it is necessary to understand
the way the exponent is stored, and its interpretation (excess-64, for
example), and the way the mantissa is stored, and its interpretation
(location of the binary point).  Also, it is important to know whether
a denormalized floating point number can be used in calculations
without causing overflow or "underflow".

The detailed specifications for your CPU chip should answer that type
of question.  This type of question is known as an "architectural"
question, so an architecture (or functional specification) manual for
your CPU would need to be consulted to fully answer it.

If this is the sort of answer you had in mind, then can you clarify
your question to indicate this, and in your clarification, can you
indicate which CPU you are using?

I see, too, in your question that you are looking for an "algorithm". 
That might mean you want to write a program, in C perhaps, that will
run on a computer and determine what its smallest floating point
number is.  That way, the program could be compliled on any computer,
and run as a test to see what the smallest floating point number is. 
If that's what you meant, then can you clarify your question to say
that?
Subject: Re: Calculating smallest positive float / double
From: wasting_time2-ga on 01 Jun 2004 14:06 PDT
 
what governs the diffrence of the smallest floating point? i know its
a hardware issue but what exactly is it? is it the amount of
electricity used to carry out the prosses?
Subject: Re: Calculating smallest positive float / double
From: parubok-ga on 02 Jun 2004 13:55 PDT
 
Hello,

Start with a value 1.00 and start dividing it by two untill u get to
the last non-zero number.

In C++:

float min_float() {
    float result = 1.00;
    while(1) {
        if((result / 2) == 0.0) {
            return result;
        }
        result = result / 2;
    }
}

double min_float() {
    double result = 1.00;
    while(1) {
        if((result / 2) == 0.0) {
            return result;
        }
        result = result / 2;
    }
}

Regards,
parubok
Subject: Re: Calculating smallest positive float / double
From: ksitze-ga on 24 Sep 2004 11:51 PDT
 
Here is my preferred solution.  This generates the smallest positive
denormalized value on the machine it is running on.  You can see that
the resulting values are smaller than those indicated by
numeric_limits::min().  On the machine I run this on,
numeric_limits::denorm_min() produces zero, not very useful IMHO.  I
"cheat" slightly, in that I use the radix specification for the
machine I'm running on rather than attempt to compute the radix value
directly.

#include <iostream>
#include <limits>

template <class T>
T minimumPositive()
{
    T result;
    T future = 1;

    do {
        result = future;
        future /= std::numeric_limits<T>::radix;
    } while (future != 0);

    return result;
} /* minimumPositive() */

int main()
{
    std::cout << std::scientific;
    std::cout << std::numeric_limits<float>::min() << std::endl;
    std::cout << minimumPositive<float>() << std::endl;
    std::cout << std::numeric_limits<double>::min() << std::endl;
    std::cout << minimumPositive<double>() << std::endl;
} /* main() */

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy