intfloat_readwrite.c File Reference

#include "common.h"
#include "intfloat_readwrite.h"

Go to the source code of this file.

Functions

double av_int2dbl (int64_t v)
float av_int2flt (int32_t v)
double av_ext2dbl (const AVExtFloat ext)
int64_t av_dbl2int (double d)
int32_t av_flt2int (float d)
AVExtFloat av_dbl2ext (double d)


Detailed Description

Portable IEEE float/double read/write functions.

Definition in file intfloat_readwrite.c.


Function Documentation

AVExtFloat av_dbl2ext ( double  d  ) 

Definition at line 76 of file intfloat_readwrite.c.

References AVExtFloat::exponent, and AVExtFloat::mantissa.

00076                                {
00077     struct AVExtFloat ext= {{0}};
00078     int e, i; double f; uint64_t m;
00079 
00080     f = fabs(frexp(d, &e));
00081     if (f >= 0.5 && f < 1) {
00082         e += 16382;
00083         ext.exponent[0] = e>>8;
00084         ext.exponent[1] = e;
00085         m = (uint64_t)ldexp(f, 64);
00086         for (i=0; i < 8; i++)
00087             ext.mantissa[i] = m>>(56-(i<<3));
00088     } else if (f != 0.0) {
00089         ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
00090         if (f != 1/0.0)
00091             ext.mantissa[0] = ~0;
00092     }
00093     if (d < 0)
00094         ext.exponent[0] |= 0x80;
00095     return ext;
00096 }

int64_t av_dbl2int ( double  d  ) 

Definition at line 60 of file intfloat_readwrite.c.

Referenced by ffm_write_header(), gxf_write_umf_media_audio(), put_amf_double(), and put_ebml_float().

00060                             {
00061     int e;
00062     if     ( !d) return 0;
00063     else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d);
00064     d= frexp(d, &e);
00065     return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53));
00066 }

double av_ext2dbl ( const AVExtFloat  ext  ) 

Definition at line 43 of file intfloat_readwrite.c.

References AVExtFloat::exponent, and AVExtFloat::mantissa.

Referenced by get_aiff_header().

00043                                        {
00044     uint64_t m = 0;
00045     int e, i;
00046 
00047     for (i = 0; i < 8; i++)
00048         m = (m<<8) + ext.mantissa[i];
00049     e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1];
00050     if (e == 0x7fff && m)
00051         return 0.0/0.0;
00052     e -= 16383 + 63;        /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
00053                              * mantissa bit is written as opposed to the
00054                              * single and double precision formats */
00055     if (ext.exponent[0]&0x80)
00056         m= -m;
00057     return ldexp(m, e);
00058 }

int32_t av_flt2int ( float  d  ) 

Definition at line 68 of file intfloat_readwrite.c.

00068                            {
00069     int e;
00070     if     ( !d) return 0;
00071     else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
00072     d= frexp(d, &e);
00073     return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
00074 }

double av_int2dbl ( int64_t  v  ) 

Definition at line 31 of file intfloat_readwrite.c.

Referenced by amf_parse_object(), ebml_read_float(), ffm_read_header(), mov_read_stsd(), and nuv_header().

00031                             {
00032     if(v+v > 0xFFEULL<<52)
00033         return 0.0/0.0;
00034     return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
00035 }

float av_int2flt ( int32_t  v  ) 

Definition at line 37 of file intfloat_readwrite.c.

Referenced by ebml_read_float(), fourxm_read_header(), and thp_read_header().

00037                            {
00038     if(v+v > 0xFF000000U)
00039         return 0.0/0.0;
00040     return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
00041 }


Generated on Thu Nov 20 05:45:32 2008 for libextractor by  doxygen 1.5.1