Searching \ for 'Float expression to integer math' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Float expression to integer math'.

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

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....


--  ---
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:      Kryddor/Te/Kaffe:
Personal homepage:
Automated home:

-- Going offline? Don't AutoReply us!
email with SET PICList DIGEST in the body

2004\08\22@113324 by Kenneth Lumia

picon face

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.


{Original Message removed}

2004\08\22@133206 by Ake Hedman

Kenneth Lumia wrote:

{Quote hidden}

>{Original Message removed}

2004\08\22@134752 by Spehro Pefhany

picon face
At 07:30 PM 8/22/2004 +0200, you wrote:

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

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"             Info for manufacturers:
Embedded software/hardware/analog  Info for designers:

-- Going offline? Don't AutoReply us!
email with SET PICList DIGEST in the body

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