## [Mingw-users] How to recover a float from binary unsigned equiv. value ?

 [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Roberto Ricardi - 2003-11-09 04:58:57 ```Hi all, I got a float single, manage it in a binary form in an unsigned int. And wish to recover the float form. The magnitudes range never be greather than +/- 32k. to manage a float we can do: Sign * 2^m * 1.F ( where m = E -127 and F = mantissa). To reconstruc with: r = 0.0 /* this is float */ n = Mantisa /* unsigned, mantissa constructed in binary */ n = n | 0x3F800000; /* this meant 'or' with E-127 = 0, positive */ now try to 'or' the binary equiv. in the float variable r = r | n; /* meant 1.F */ compiler cant manage float and unsigned 'or', maybe assuming not both 32 bits long ? the next cant be managed too, of course: r = 2^m * r; /* meant 2^m * 1.F */ How can I construct a float from a binary unsigned equiv. value ? Thanks a lot in advance Rob ```

 [Mingw-users] =?ISO-8859-1?Q?=BF_How_to_read_an_I/O_ports_in_m?= =?ISO-8859-1?Q?ingw_=3F?= From: Roberto Ricardi - 2003-10-27 02:10:54 ```Hi all, How can I read an I/O port from c (not c++) code in mingw?. The only source Im read, by the while, was 'mnsd' info and http://www.naughter.com/ (free app to serial ports, with MFC, VC). Thanks in advance Roberto ```
 [Mingw-users] =?iso-8859-1?Q?Re:_=5BMingw-users=5D_=BF_How_to_read_an_I/O_ports_in_mi?= =?iso-8859-1?Q?ngw_=3F?= From: psksvp - 2003-10-27 11:07:07 ```depend on your os, NT4, W2K and XP won't allow you to real i/o port direc= tly in user mode. you will need a software call Port95NT which will allow you= to user api inport and outport. but I think, the best way is to use CreateFile(..) api psksvp ----- Original Message -----=20 From: "Roberto Ricardi" To: Sent: Monday, October 27, 2003 1:05 PM Subject: [Mingw-users] =BF How to read an I/O ports in mingw ? > Hi all, > > How can I read an I/O port from c (not c++) code in mingw?. The only > source Im read, by the while, was 'mnsd' info and > http://www.naughter.com/ (free app to serial ports, with MFC, VC). > > Thanks in advance > > Roberto > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: The SF.net Donation Program. > Do you like what SourceForge.net is doing for the Open > Source Community? Make a contribution, and help us add new > features and functionality. Click here: http://sourceforge.net/donate/ > _______________________________________________ > MinGW-users mailing list > MinGW-users@... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > ```
 [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Roberto Ricardi - 2003-11-09 04:58:57 ```Hi all, I got a float single, manage it in a binary form in an unsigned int. And wish to recover the float form. The magnitudes range never be greather than +/- 32k. to manage a float we can do: Sign * 2^m * 1.F ( where m = E -127 and F = mantissa). To reconstruc with: r = 0.0 /* this is float */ n = Mantisa /* unsigned, mantissa constructed in binary */ n = n | 0x3F800000; /* this meant 'or' with E-127 = 0, positive */ now try to 'or' the binary equiv. in the float variable r = r | n; /* meant 1.F */ compiler cant manage float and unsigned 'or', maybe assuming not both 32 bits long ? the next cant be managed too, of course: r = 2^m * r; /* meant 2^m * 1.F */ How can I construct a float from a binary unsigned equiv. value ? Thanks a lot in advance Rob ```
 Re: [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Peter Barada - 2003-11-09 05:42:05 ```>I got a float single, manage it in a binary form in an unsigned int. And >wish to recover the float form. >The magnitudes range never be greather than +/- 32k. > >to manage a float we can do: Sign * 2^m * 1.F ( where m = E -127 and F >= mantissa). > >To reconstruc with: > > r = 0.0 /* this is float */ > n = Mantisa /* unsigned, mantissa constructed in binary */ > n = n | 0x3F800000; /* this meant 'or' with E-127 = 0, positive */ > >now try to 'or' the binary equiv. in the float variable > > r = r | n; /* meant 1.F */ > >compiler cant manage float and unsigned 'or', maybe assuming not both 32 >bits long ? >the next cant be managed too, of course: > > r = 2^m * r; /* meant 2^m * 1.F */ > >How can I construct a float from a binary unsigned equiv. value ? Use a union to hold bothe the float and the binary representation of the float: float transmute(unsinged int mantissa) float f; union { float f; unsigned int i; } fi; fi.i = mantissa; /* Mantissa is a value in the lower 23 bits , a fraction where 0x007ffff is 1 ulp less than one. */ fi.i |= 0x3f800000; /* set exponent and sign bits */ f = fi.f; /* interpret fi.i as binary representaiton of a float */ return(f); } -- Peter Barada peter@... ```
 Re: [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Duncan Murdoch - 2003-11-09 12:52:06 ```On Sun, 9 Nov 2003 00:41:48 -0500 (EST), you wrote: >Use a union to hold bothe the float and the binary representation of >the float: > >float transmute(unsinged int mantissa) > float f; > union { > float f; > unsigned int i; > } fi; > > fi.i = mantissa; /* Mantissa is a value in the lower 23 bits , a > fraction where 0x007ffff is 1 ulp less than one. */ > fi.i |= 0x3f800000; /* set exponent and sign bits */ > f = fi.f; /* interpret fi.i as binary representaiton of a float */ > return(f); >} That looks wrong. The mantissa should be normalized, with the most significant bit (always 1) not stored. Zero is special-cased to have both zero exponent and mantissa. Duncan Murdoch ```
 Re: [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Peter Barada - 2003-11-09 19:26:34 ```>>Use a union to hold bothe the float and the binary representation of >>the float: >> >>float transmute(unsinged int mantissa) >> float f; >> union { >> float f; >> unsigned int i; >> } fi; >> >> fi.i = mantissa; /* Mantissa is a value in the lower 23 bits , a >> fraction where 0x007ffff is 1 ulp less than one. */ >> fi.i |= 0x3f800000; /* set exponent and sign bits */ >> f = fi.f; /* interpret fi.i as binary representaiton of a float */ >> return(f); >>} > >That looks wrong. The mantissa should be normalized, with the most >significant bit (always 1) not stored. Zero is special-cased to have >both zero exponent and mantissa. > >Duncan Murdoch Yes, you're right. Here's a function that *should* do it all. I've done some cursory tested it, but nothing exhaustive... #define SPF_PREC 23 /* how many bits of precision in a IEEE single-precision float */ #define ASSUMED_ONE (1<= 32) { fi.i = 0x7fc00000; return (fi.f); } sign = 0; if (frac < 0) { frac = -frac; sign = 0x80000000; /* set the sign bit */ } else if (!frac) return (float)0.0; /* weed out special case of zero */ /* If the fraction is 1, return +/- 1.0 */ if (frac == (1< SPF_PREC) frac >>= (bits - SPF_PREC); else frac <<= (SPF_PREC - bits); /* start with an exponent of 1 */ exponent = 0x3f800000; /* Now normalize the mantissa until we have the first significant bit in the assumed one position. */ while (!(frac & ASSUMED_ONE)) { exponent -= EXPONE; frac <<= 1; } /* clear the assumed one so it doesn't pollute the exponent */ frac &= ~ASSUMED_ONE; fi.i = sign | exponent | frac; return (fi.f); } -- Peter Barada peter@... ```
 Re: [Mingw-users] How to recover a float from binary unsigned equiv. value ? From: Roberto Ricardi - 2003-11-11 06:44:09 ```Thanks a lot, Peter & Duncan. union work great ! Roberto Ricardi wrote: > Hi all, > > I got a float single, manage it in a binary form in an unsigned int. > And wish to recover the float form. > The magnitudes range never be greather than +/- 32k. > > to manage a float we can do: Sign * 2^m * 1.F ( where m = E -127 and > F = mantissa). > > To reconstruc with: > > r = 0.0 /* this is float */ > n = Mantisa /* unsigned, mantissa constructed in binary */ > n = n | 0x3F800000; /* this meant 'or' with E-127 = 0, positive */ > > now try to 'or' the binary equiv. in the float variable > > r = r | n; /* meant 1.F */ > > compiler cant manage float and unsigned 'or', maybe assuming not both > 32 bits long ? > the next cant be managed too, of course: > > r = 2^m * r; /* meant 2^m * 1.F */ > > How can I construct a float from a binary unsigned equiv. value ? > > Thanks a lot in advance > > Rob > > > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: ApacheCon 2003, > 16-19 November in Las Vegas. Learn firsthand the latest > developments in Apache, PHP, Perl, XML, Java, MySQL, > WebDAV, and more! http://www.apachecon.com/ > _______________________________________________ > MinGW-users mailing list > MinGW-users@... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > > ```