Skip to content

Compressibility unit conversion between InverseKilopascal and InversePoundForcePerSquareInch is inverted #1667

@ckschiefer

Description

@ckschiefer

Describe the bug

The Compressibility type produces incorrect results when converting between InverseKilopascal and InversePoundForcePerSquareInch. The conversion factor is being applied in the wrong direction — the result is the reciprocal of the correct value.

Expected behavior

Since 1 psi = 6.894757293 kPa, one "per kilopascal" represents a larger compressibility than one "per psi". Therefore:

  • 1 kPa⁻¹ = 6.894757293 psi⁻¹
  • 1 psi⁻¹ = 0.145037738 kPa⁻¹

Actual behavior

UnitsNet returns the reciprocal of the correct values:

  • 1 kPa⁻¹ = 0.145037738 psi⁻¹
  • 1 psi⁻¹ = 6.894757293 kPa⁻¹

To reproduce

var c = Compressibility.FromInverseKilopascals(1.0);
Console.WriteLine(c.ToUnit(CompressibilityUnit.InversePoundForcePerSquareInch));
// Prints: 0.145037738 psi⁻¹  (expected: 6.894757293 psi⁻¹)

Root cause

The conversion factor between InverseKilopascal and InversePoundForcePerSquareInch appears to be inverted in Compressibility.json. The FromUnitToBaseFunc and FromBaseToUnitFunc for InversePoundForcePerSquareInch are likely applying multiplication where division is needed, or vice versa.

This can be verified by cross-checking against the Pressure type, which correctly defines 1 psi = 6.894757293 kPa. For inverse pressure units, the conversion factor flips:

// Pressure type correctly gives:
double kpaPerPsi = Pressure.FromPoundsForcePerSquareInch(1.0).Kilopascals; // 6.894757293

// For compressibility (inverse pressure), the conversion is the reciprocal:
// 1 kPa^-1 = kpaPerPsi psi^-1 = 6.894757293 psi^-1
// But UnitsNet Compressibility gives: 1/kpaPerPsi = 0.145037738

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions