Large negative pressures

Linus Torvalds torvalds at linux-foundation.org
Wed Aug 7 09:31:35 PDT 2019


On Wed, Aug 7, 2019 at 6:42 AM Robert Helling <helling at lmu.de> wrote:
>
> The planner tries computes the consumed gas for the dives it plans. It computes it in terms of litres of gas. Then, in the end, using the assumed cylinder size this is converted into a pressure drop.
>
> As you know, internally, all our pressures are in mbar and stored in pressure_t which happens to be an int32_t. Its maximal value corresponds to about 200bar.

No.

The maximal value for a int32_t in mbar is over 2 _billion_ mbar. So
the maximal value corresponds not to 200 bar, but to 2 _million_ bar.

We do seem to have a comment in the unit header file about 2000 bar,
which is garbage, but it's certainly the case that the "uint32_t" is
_enough_ for up to 2000 bar, which is not a realistic cylinder
pressure value. It's just fo far beyond that limit that it's not even
funny.

If you have something that overflows into millions of bars, you are
doing something completely wrong.

> 2) Make pressure_t (and related variable) int64_t,

Absolutely not. See above. That would be entirely crazy.

Now, it is possible that while you're doing some intermediate
calculations, you might end up having temporary values that are bigger
than int32_t (say, because you're multiplying millimeters by millibars
and haven't reduced the range in the intermediate values or whatever).

But that's a totally different problem. That just means that some
calculation internally may need to be done in another type, or the
operations need to be done in another order so that you don't overflow
intermediate values.

And yes, we do seem to have some problem like that, because your
screenshot shows something like "-1634392 bar" in there.

But note how that is negative _millions_ of bars. Again, our
"pressure_t" range is not the problem. The problem is somewhere else
in the planner doing math.

               Linus


More information about the subsurface mailing list