Kenneth Lumia wrote: >Ake, > >Before you get too involved with trying to figure out a method, >you may want to try to reduce the number of significant digits >in the problem. The final method chosen would depend on the >accuracy required on the output. I would think you could round >many of the factors to fewer digits and still get a reasonably >accurate answer. Try using a spreadsheet with columns setup >using the "full accuracy" numbers, and other columns with the >coefficients rounded to 3 or 4 digits. In otherwords, simplify >before you design. > >Once done, you can then decide where the decimal point >should go and then multiply the coefficients by powers of 2 >and keep track of where the decimal point should be. >A convenient multiple is 2**8 which will fix the decimal >between two bytes. > > >Ken > > >----- Original Message ----- >From: "Ake Hedman" >To: >Sent: Sunday, August 22, 2004 10:55 AM >Subject: Float expression to integer math > > >I'm totally stuck with a math problem and though I should ask the list >for help as a last resort > >I need to calculate the dew point in C using integer maths. The dew >point can be calculated with the following expression > >logEw =3D ( 0.66077 + ( ( 7.5 * T ) / (237.3 + T ) ) + ( log10(RH) - 2= ) >dp =3D ( (0.66077 - logEw ) * 237.3 ) / ( logEw - 8.16077 ) > >which is derived from > >EW =3D 10^ ( 0.66077+(7.5*T/ (237.3+T)) ) // this is the saturation >vapor pressure over water. >EW_RH =3D EW * RH / 100 // multiply with >relative humidity >Dp =3D ((0.66077-log10(EW_RH))*237.3) / (log10(EW_RH)-8.16077) // this = is >the dewpoint > >My usual approach to this is to try to make everything in the expression >integers so I end up with a result that is a number of factors bigger >than the actual and that way preserving decimals. But in this case an >long is to small for such an approach. > >I can get the ( log10(RH) - 2 ) expression from a table. > >My input values for T and RH is t =3D 100*T and rh =3D 100 * RH that is = both >is preserved with two decimals. > >Any suggestions appreciated.... > >Regards >/Ake > > > >-- > --- >Ake Hedman (YAP - Yet Another Programmer) >eurosource, Brattbergavdgen 17, 820 50 LOS, Sweden >Phone: (46) 657 413430 Cellular: (46) 73 84 84 102 >Company home: http://www.eurosource.se >Kryddor/Te/Kaffe: http://www.brattberg.com >Personal homepage: http://www.eurosource.se/akhe >Automated home: http://www.vscp.org > >-- >http://www.piclist.com#nomail Going offline? Don't AutoReply us! >email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > >-- >http://www.piclist.com#nomail Going offline? Don't AutoReply us! >email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > =20 > Ken, thanks for setting me on the track. After some analysis in the spread=20 sheet this turned out to be trivial (as always... ). Thanks again! Regards /Ake --=20 --- Ake Hedman (YAP - Yet Another Programmer) eurosource, Brattbergav=E4gen 17, 820 50 LOS, Sweden Phone: (46) 657 413430 Cellular: (46) 73 84 84 102 Company home: http://www.eurosource.se =20 Kryddor/Te/Kaffe: http://www.brattberg.com Personal homepage: http://www.eurosource.se/akhe Automated home: http://www.vscp.org -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body