Searching \ for 'Float expression to integer math' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=math
Search entire site for: 'Float expression to integer math'.

Truncated match.
'Float expression to integer math'
2004\08\22@105532 by

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 = ( 0.66077 + ( ( 7.5 * T )  /  (237.3 + T ) ) + ( log10(RH) - 2 )
dp = ( (0.66077 - logEw ) * 237.3 )  /  ( logEw - 8.16077  )

which is derived from

EW = 10^ ( 0.66077+(7.5*T/ (237.3+T)) )     //  this is the saturation vapor pressure over water.
EW_RH = EW * RH / 100                             // multiply with relative humidity
Dp = ((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 = 100*T and rh = 100 * RH that is both is preserved with two decimals.

Any suggestions appreciated....

Regards
/Ake

--  ---
Ake Hedman (YAP - Yet Another Programmer)
eurosource, Brattbergavägen 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 listservmitvma.mit.edu with SET PICList DIGEST in the body

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
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 removed}
Kenneth Lumia wrote:

{Quote hidden}

>{Original Message removed}
At 07:30 PM 8/22/2004 +0200, you wrote:

>Ken,
>
>thanks for setting me on the track. After some analysis in the spread
>sheet this turned out to be trivial (as always... ). Thanks again!
>
>Regards
>/Ake

Glad you got it to work. Regular C is not very well suited to this sort
of thing because it lacks fractional multiplication and division. Of course
they can be implemented with assembler routines while we wait (& wait) for
proposed embedded extensions.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...