[R] tried half-precision but "size 2 is unknown on this machine"

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Jan 4 18:19:34 CET 2015


On 04/01/2015 12:12, Duncan Murdoch wrote:
> On 04/01/2015 12:31 AM, Mike Miller wrote:
>> It's an IEEE standard format:
>>
>> http://en.wikipedia.org/wiki/Half-precision_floating-point_format#IEEE_754_half-precision_binary_floating-point_format:_binary16
>>
>> This is what I see:
>>
>>> writeBin(vec , con, size=2 )
>> Error in writeBin(vec, con, size = 2) : size 2 is unknown on this machine
>>
>> I'm not sure what the machine has to do with it.  It's really up to the
>> software, isn't it?
>
> Yes, but R relies on the underlying C run-time library for a lot of
> things like this.  On your platform, is there a C type corresponding to
> half precision?  If so, let us know the details, and we'll possibly add
> it to writeBin.

There is a IEC60559 (aka IEEE 754) 'half-precision floating-point type', 
but I know of no support by a C runtime on any platform I have used 
(there is a lot more in IEC60559 which is almost never supported).

>> Is there a way to get R to read/write half-precision numbers (binary16)?
>
> If it's not supported by the C run-time library and has to be done
> entirely using other types, that's the sort of thing that belongs in a
> user-contributed package.  I'm not aware of one that already has it, so
> you may have to write this yourself.

There is a C++ library called 'half' which could be wrapped.  See 
http://half.sourceforge.net/ : it has a lot of compiler-specific code.

>
> Duncan Murdoch
>
>>
>> It isn't a big deal for me because unsigned 16-bit integers are working
>> well enough, but I'd like to have an answer for people who ask why I make
>> them divide by 1000 all the time.  ;-)
>>
>> Mike


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK



More information about the R-help mailing list