float32 single etc

David Bateman dbateman at dbateman.org
Tue May 5 17:22:57 CDT 2009


david at materialintelligencellc.com wrote:
>
> To whom it concerns,
>
> I’m sure this is known but not well documented. I’m looking for some 
> feedback on this issue more so than a fix, although it should be fixed.
>
> It is known that the function single(), which converts a value to 
> single precision floating point will return a double precision due to 
> the fact that “Octave does not yet have a single-precision numeric 
> data type”.
>
> Are functions like fread(fid, size, precision) affected by this 
> statement? In other words if I open a files with a string of 1000 
> single precision floating point and read them one at a time (or in 
> blocks as an array) using fread(fid,[a,b],’float’) will it read 32 
> bits at a time or 64? Same question for ‘float32’ or ‘single’.
>
> Thanks,
> David
>
The development version of Octave has the "single" function and a 32bit 
real type. However as the question was about Octave 3.0.x, yes fread is 
affect by this statement, this is all controlled by the 
liboctave/data-conv.cc(read_doubles) function where the code

case LS_FLOAT:
{
OCTAVE_LOCAL_BUFFER (float, ptr, len);
is.read (reinterpret_cast<char *> (ptr), 4 * len);
do_float_format_conversion (ptr, len, fmt);
for (int i = 0; i < len; i++)
data[i] = ptr[i];
}
break;

reads all of the data as a single block into a temporary buffer and then 
converts to the native float type before finally copying the data to 
double array "data" that is returned from the function. As far as I can 
see this code should be called in 3.0.x for all of the cases you mention

D.

-- 
David Bateman                                dbateman at dbateman.org
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)



More information about the Bug-octave mailing list