Amazing at how many spots we are re-implementing the wheel.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
extern double get_volume_units(unsigned int mm, int *frac, const char **units);
extern double get_temp_units(unsigned int mm, const char **units);
-static inline double bar_to_atm(double bar)
-{
- return bar / 1.01325;
-}
-
static inline double ml_to_cuft(int ml)
{
return ml / 28316.8466;
}
-static inline double cuft_to_ml(double cuft)
+static inline double cuft_to_l(double cuft)
{
return cuft * 28.3168466;
}
return pressure.mbar * 0.0145037738 + 0.5;
}
+static inline double bar_to_atm(double bar)
+{
+ return bar / 1.01325;
+}
+
static inline double to_ATM(pressure_t pressure)
{
return pressure.mbar / 1013.25;
gpointer data)
{
int value;
- const double liters_per_cuft = 28.317;
const char *fmt;
char buffer[16];
double sac;
break;
case CUFT:
fmt = "%4.2f";
- sac /= liters_per_cuft;
+ sac = ml_to_cuft(sac * 1000);
break;
}
snprintf(buffer, sizeof(buffer), fmt, sac);
if (!size)
continue;
- kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0;
+ kilo_atm = (to_ATM(cyl->start) - to_ATM(cyl->end)) / 1000.0;
/* Liters of air at 1 atm == milliliters at 1k atm*/
airuse += kilo_atm * size;
}
if (pressure && output_units.volume == CUFT) {
- volume = cuft_to_ml(volume);
+ volume = cuft_to_l(volume);
volume /= bar_to_atm(pressure);
}
/* Is it in cuft and psi? */
if (psi) {
double bar = psi_to_bar(psi);
- double airvolume = cuft_to_ml(size);
+ double airvolume = cuft_to_l(size) * 1000.0;
double atm = bar_to_atm(bar);
ml = airvolume / atm + 0.5;
if (!val.fp)
break;
/* cbar to atm */
- atm = (val.fp / 100) / 1.01325;
+ atm = bar_to_atm(val.fp * 10);
/*
* atm to cm. Why not mm? The precision just isn't
* there.
if (type->description)
return;
- cuft = type->size.mliter / 28317.0;
+ cuft = ml_to_cuft(type->size.mliter);
cuft *= to_ATM(type->workingpressure);
- psi = type->workingpressure.mbar / 68.95;
+ psi = to_PSI(type->workingpressure);
switch (psi) {
case 2300 ... 2500: /* 2400 psi: LP tank */
return;
if (input_units.volume == CUFT || import_source == SUUNTO) {
- volume_of_air = type->size.mliter * 28.317; /* milli-cu ft to milliliter */
+ /* confusing - we don't really start from ml but millicuft !*/
+ volume_of_air = cuft_to_l(type->size.mliter);
atm = to_ATM(type->workingpressure); /* working pressure in atm */
volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */
type->size.mliter = volume + 0.5;
{
double atm, cm;
- atm = (value / 100.0) / 1.01325;
+ atm = bar_to_atm(value / 100.0);
cm = 100 * atm + 0.5;
return( (cm > 0) ? 10 * (long)cm : 0);
}