octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New randi function added


From: Rik
Subject: Re: New randi function added
Date: Sun, 15 Aug 2010 16:56:22 -0700

Jordi GutiƩrrez Hermoso wrote:
> On 15 August 2010 17:04, Rik <address@hidden> wrote:
>> During the coding I came across a need to know the largest integer that
>> would fit within a given data class.  This was easy for the integer classes
>> (intmax("CLASS")) and for doubles there is bitmax().  Is there equivalent
>> functionality for singles?
> 
> Why not wrap C++'s <limits> header?
> 
>      #include <iostream>
>      #include <limits>
> 
>      using namespace std;
> 
>      int main()
>      {
>        cout << "Max float: " << numeric_limits<float>::max() << endl;
>      }
> 
> You can use is_iec559 if you want to ensure that float is 4 bytes,
> although I can't imagine that anyone would be using a non-IEEE754
> implementation of C++ for compiling Octave. I would expect that there
> are already several assumptions in Octave sources that
> numeric_limits<float>::is_iec559 is true.

It would appear that you are right about assumptions.  I looked up the
existing bitmax code in bitfcns.cc:526 and I find

retval = (static_cast<double> (0x1FFFFFFFFFFFFFLL));

which is surely a hard-coded constant.  On the other hand, configure checks
and adds compiler flags for IEEE754 behavior so perhaps you're right that
we are guaranteed IEEE754 conformance.

The <limits> code doesn't quite work as it determines the largest floating
point value that <float> can hold and I need the largest integer that
<float> can hold.  For that I need the number of bits in the mantissa of
the representation.

So, rephrasing the question.  Is there any issue with extending bitmax to
include a class argument and having the default for single be 24 bits of
precision.  (See
http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers)

--Rik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]