Repository: angularsen/UnitsNet (2026-07-25T10:37:47Z)

Issue:
Compressibility unit conversion between InverseKilopascal and InversePoundForcePerSquareInch is inverted
**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**

```csharp
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:

```csharp
// 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
```


Discussion:
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was automatically closed due to inactivity.
Please reopen this issue. It is a bug.



Patch:
diff --git a/Common/UnitDefinitions/Compressibility.json b/Common/UnitDefinitions/Compressibility.json
index 7d3b14cb30..d8c28fae95 100644
--- a/Common/UnitDefinitions/Compressibility.json
+++ b/Common/UnitDefinitions/Compressibility.json
@@ -28,8 +28,8 @@
     {
       "SingularName": "InverseKilopascal",
       "PluralName": "InverseKilopascals",
-      "FromUnitToBaseFunc": "{x} * 1e3",
-      "FromBaseToUnitFunc": "{x} / 1e3",
+      "FromUnitToBaseFunc": "{x} / 1e3",
+      "FromBaseToUnitFunc": "{x} * 1e3",
       "Localization": [
         {
           "Culture": "en-US",
@@ -40,8 +40,8 @@
     {
       "SingularName": "InverseMegapascal",
       "PluralName": "InverseMegapascals",
-      "FromUnitToBaseFunc": "{x} * 1e6",
-      "FromBaseToUnitFunc": "{x} / 1e6",
+      "FromUnitToBaseFunc": "{x} / 1e6",
+      "FromBaseToUnitFunc": "{x} * 1e6",
       "Localization": [
         {
           "Culture": "en-US",
@@ -52,8 +52,8 @@
     {
       "SingularName": "InverseAtmosphere",
       "PluralName": "InverseAtmospheres",
-      "FromUnitToBaseFunc": "{x} * 101325",
-      "FromBaseToUnitFunc": "{x} / 101325",
+      "FromUnitToBaseFunc": "{x} / 101325",
+      "FromBaseToUnitFunc": "{x} * 101325",
       "Localization": [
         {
           "Culture": "en-US",
@@ -64,8 +64,8 @@
     {
       "SingularName": "InverseMillibar",
       "PluralName": "InverseMillibars",
-      "FromUnitToBaseFunc": "{x} * 100",
-      "FromBaseToUnitFunc": "{x} / 100",
+      "FromUnitToBaseFunc": "{x} / 100",
+      "FromBaseToUnitFunc": "{x} * 100",
       "Localization": [
         {
           "Culture": "en-US",
@@ -76,8 +76,8 @@
     {
       "SingularName": "InverseBar",
       "PluralName": "InverseBars",
-      "FromUnitToBaseFunc": "{x} * 1e5",
-      "FromBaseToUnitFunc": "{x} / 1e5",
+      "FromUnitToBaseFunc": "{x} / 1e5",
+      "FromBaseToUnitFunc": "{x} * 1e5",
       "Localization": [
         {
           "Culture": "en-US",
@@ -88,8 +88,8 @@
     {
       "SingularName": "InversePoundForcePerSquareInch",
       "PluralName": "InversePoundsForcePerSquareInch",
-      "FromUnitToBaseFunc": "{x} * 6.894757293168361e3",
-      "FromBaseToUnitFunc": "{x} / 6.894757293168361e3",
+      "FromUnitToBaseFunc": "{x} / 6.894757293168361e3",
+      "FromBaseToUnitFunc": "{x} * 6.894757293168361e3",
       "Localization": [
         {
           "Culture": "en-US",
diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
index 6913b3a5fa..94c6a08060 100644
--- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
@@ -768,20 +768,20 @@ private bool TryToUnit(CompressibilityUnit unit, [NotNullWhen(true)] out Compres
             Compressibility? convertedOrNull = (Unit, unit) switch
             {
                 // CompressibilityUnit -> BaseUnit
-                (CompressibilityUnit.InverseAtmosphere, CompressibilityUnit.InversePascal) => new Compressibility(_value * 101325, CompressibilityUnit.InversePascal),
-                (CompressibilityUnit.InverseBar, CompressibilityUnit.InversePascal) => new Compressibility(_value * 1e5, CompressibilityUnit.InversePascal),
-                (CompressibilityUnit.InverseKilopascal, CompressibilityUnit.InversePascal) => new Compressibility(_value * 1e3, CompressibilityUnit.InversePascal),
-                (CompressibilityUnit.InverseMegapascal, CompressibilityUnit.InversePascal) => new Compressibility(_value * 1e6, CompressibilityUnit.InversePascal),
-                (CompressibilityUnit.InverseMillibar, CompressibilityUnit.InversePascal) => new Compressibility(_value * 100, CompressibilityUnit.InversePascal),
-                (CompressibilityUnit.InversePoundForcePerSquareInch, CompressibilityUnit.InversePascal) => new Compressibility(_value * 6.894757293168361e3, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InverseAtmosphere, CompressibilityUnit.InversePascal) => new Compressibility(_value / 101325, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InverseBar, CompressibilityUnit.InversePascal) => new Compressibility(_value / 1e5, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InverseKilopascal, CompressibilityUnit.InversePascal) => new Compressibility(_value / 1e3, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InverseMegapascal, CompressibilityUnit.InversePascal) => new Compressibility(_value / 1e6, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InverseMillibar, CompressibilityUnit.InversePascal) => new Compressibility(_value / 100, CompressibilityUnit.InversePascal),
+                (CompressibilityUnit.InversePoundForcePerSquareInch, CompressibilityUnit.InversePascal) => new Compressibility(_value / 6.894757293168361e3, CompressibilityUnit.InversePascal),
 
                 // BaseUnit -> CompressibilityUnit
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseAtmosphere) => new Compressibility(_value / 101325, CompressibilityUnit.InverseAtmosphere),
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseBar) => new Compressibility(_value / 1e5, CompressibilityUnit.InverseBar),
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseKilopascal) => new Compressibility(_value / 1e3, CompressibilityUnit.InverseKilopascal),
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMegapascal) => new Compressibility(_value / 1e6, CompressibilityUnit.InverseMegapascal),
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMillibar) => new Compressibility(_value / 100, CompressibilityUnit.InverseMillibar),
-                (CompressibilityUnit.InversePascal, CompressibilityUnit.InversePoundForcePerSquareInch) => new Compressibility(_value / 6.894757293168361e3, CompressibilityUnit.InversePoundForcePerSquareInch),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseAtmosphere) => new Compressibility(_value * 101325, CompressibilityUnit.InverseAtmosphere),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseBar) => new Compressibility(_value * 1e5, CompressibilityUnit.InverseBar),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseKilopascal) => new Compressibility(_value * 1e3, CompressibilityUnit.InverseKilopascal),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMegapascal) => new Compressibility(_value * 1e6, CompressibilityUnit.InverseMegapascal),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMillibar) => new Compressibility(_value * 100, CompressibilityUnit.InverseMillibar),
+                (CompressibilityUnit.InversePascal, CompressibilityUnit.InversePoundForcePerSquareInch) => new Compressibility(_value * 6.894757293168361e3, CompressibilityUnit.InversePoundForcePerSquareInch),
 
                 _ => null
             };


Test patch:
diff --git a/UnitsNet.Tests/CustomCode/CompressibilityTests.cs b/UnitsNet.Tests/CustomCode/CompressibilityTests.cs
index 9f67b1223c..0c157d9c6a 100644
--- a/UnitsNet.Tests/CustomCode/CompressibilityTests.cs
+++ b/UnitsNet.Tests/CustomCode/CompressibilityTests.cs
@@ -18,19 +18,52 @@
 // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.
 
 using System;
+using UnitsNet.Units;
+using Xunit;
 
 namespace UnitsNet.Tests.CustomCode
 {
     public class CompressibilityTests : CompressibilityTestsBase
     {
-        // Override properties in base class here
-
         protected override double InversePascalsInOneInversePascal => 1;
-        protected override double InverseMillibarsInOneInversePascal => 1e-2;
-        protected override double InverseKilopascalsInOneInversePascal => 1e-3;
-        protected override double InverseMegapascalsInOneInversePascal => 1e-6;
-        protected override double InverseBarsInOneInversePascal => 1e-5;
-        protected override double InversePoundsForcePerSquareInchInOneInversePascal => 1.450377377302092151542e-4;
-        protected override double InverseAtmospheresInOneInversePascal => 9.86923266716013e-6;
+        protected override double InverseMillibarsInOneInversePascal => 100;
+        protected override double InverseKilopascalsInOneInversePascal => 1e3;
+        protected override double InverseMegapascalsInOneInversePascal => 1e6;
+        protected override double InverseBarsInOneInversePascal => 1e5;
+        protected override double InversePoundsForcePerSquareInchInOneInversePascal => 6.894757293168361e3;
+        protected override double InverseAtmospheresInOneInversePascal => 101325;
+
+        [Fact]
+        public void InverseKilopascalToInversePoundForcePerSquareInch()
+        {
+            Compressibility compressibility = Compressibility.FromInverseKilopascals(1);
+
+            // 1 psi = 6.894757293168361 kPa, so 1 kPa^-1 = 6.894757293168361 psi^-1.
+            AssertEx.EqualTolerance(6.894757293168361, compressibility.InversePoundsForcePerSquareInch, 1e-12);
+        }
+
+        [Fact]
+        public void InversePoundForcePerSquareInchToInverseKilopascal()
+        {
+            Compressibility compressibility = Compressibility.FromInversePoundsForcePerSquareInch(1);
+
+            // 1 psi = 6.894757293168361 kPa, so 1 psi^-1 = 0.14503773773020923 kPa^-1.
+            AssertEx.EqualTolerance(0.14503773773020923, compressibility.InverseKilopascals, 1e-12);
+        }
+
+        [Theory]
+        [InlineData(CompressibilityUnit.InverseMillibar, 100)]
+        [InlineData(CompressibilityUnit.InverseKilopascal, 1e3)]
+        [InlineData(CompressibilityUnit.InverseMegapascal, 1e6)]
+        [InlineData(CompressibilityUnit.InverseBar, 1e5)]
+        [InlineData(CompressibilityUnit.InverseAtmosphere, 101325)]
+        [InlineData(CompressibilityUnit.InversePoundForcePerSquareInch, 6.894757293168361e3)]
+        public void OneInversePascalEqualsPressureFactorInInversePressureUnit(CompressibilityUnit unit, double expected)
+        {
+            Compressibility compressibility = Compressibility.FromInversePascals(1);
+
+            // If 1 target pressure unit equals N pascals, then 1 Pa^-1 equals N target-unit^-1.
+            AssertEx.EqualTolerance(expected, compressibility.As(unit), 1e-12);
+        }
     }
 }