comparison srf2fastq/io_lib-1.12.2/io_lib/fpoint.c @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 /*
2 * Copyright (c) Medical Research Council 1994. All rights reserved.
3 *
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * this copyright and notice appears in all copies.
7 *
8 * This file was written by James Bonfield, Simon Dear, Rodger Staden,
9 * as part of the Staden Package at the MRC Laboratory of Molecular
10 * Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
11 *
12 * MRC disclaims all warranties with regard to this software.
13 */
14
15 #include <math.h>
16 #include "io_lib/fpoint.h"
17 /*
18 extern double log ( double x ) ;
19 extern double exp ( double x ) ;
20 */
21 #define IEEE
22
23 float int_to_float(int in)
24 /*
25 ** interpret the integer in as a
26 ** floating point number in IEEE format
27 */
28 {
29 /*
30 Assume `in' is stored as a float according to the
31 ANSI IEEE 754-1985 standard. See the tables below:
32
33 s = sign ( 1 bit)
34 e = biased exponent (8 bits)
35 f = fraction (23 bits)
36
37 floating point number = (-1)^s 2^(e-127) 1.f
38
39 Bits Name Content
40 31 Sign 1 iff number is negative
41 23-30 Exponent Eight-Bit exponent, biased by 127
42 0-22 Fraction 23-bit fraction component of normalised significant.
43 The "one" bit is "hidden"
44
45 If IEEE floating point format is supported on your machine...
46 ensure there is a #define IEEE somewhere.
47 */
48
49 #ifdef IEEE
50 union {
51 int i;
52 float f;
53 } cvt;
54 cvt.i = in;
55 return cvt.f;
56 #else
57 int fraction;
58 int exponent;
59 int sign;
60
61 fraction = in & ( (1<<23)-1 );
62 exponent = (in >> 23) & ( (1<<8)-1 );
63 sign = (in >> 31);
64
65 return
66 (float) (
67 (sign?-1.0:1.0) *
68 exp ( log ( (double) 2.0) * (double) (exponent - 127 - 23) ) *
69 (double) ((1<<23)+fraction)) ;
70 #endif
71 }