general: simplify a few unit manipulations

Now that we have defined addition and subtraction on unit
classes, let's use them in a few examples.

Yes, some of these are a bit pointless, because they are
of the kind
        a.mbar - b.mbar => (a-b).mbar

However, these probably should be further simplified
by storing the result in a unit type.

This commit is mostly a proof-of-concept.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-09-02 20:42:05 +02:00 committed by bstoeger
parent 729cc16fc5
commit 110e64bc66
14 changed files with 59 additions and 68 deletions

View file

@ -185,12 +185,12 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
return;
mean_depth.mm = (old_depth + new_depth) / 2;
gas_used.mliter = lrint(d->depth_to_atm(mean_depth.mm) * sac / 60 * duration * factor / 1000);
cyl->gas_used.mliter += gas_used.mliter;
cyl->gas_used += gas_used;
if (in_deco)
cyl->deco_gas_used.mliter += gas_used.mliter;
cyl->deco_gas_used += gas_used;
if (cyl->type.size.mliter) {
delta_p.mbar = lrint(gas_used.mliter * 1000.0 / cyl->type.size.mliter * gas_compressibility_factor(cyl->gasmix, cyl->end.mbar / 1000.0));
cyl->end.mbar -= delta_p.mbar;
cyl->end -= delta_p;
}
}