Skip to content

Commit db0af8d

Browse files
Merge branch 'master' into development
2 parents 4c7db93 + 5034d5c commit db0af8d

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

SpiceSharpBehavioral/Builders/Functions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ public static double RampDerivative(double arg)
293293
/// <returns>The interpolated value.</returns>
294294
public static double Pwl(double arg, Point[] data)
295295
{
296+
if (arg <= data[0].X)
297+
{
298+
return data[0].Y;
299+
}
300+
301+
if (arg >= data[data.Length - 1].X)
302+
{
303+
return data[data.Length - 1].Y;
304+
}
305+
296306
// Narrow in on the index for the piece-wise linear function
297307
int k0 = 0, k1 = data.Length;
298308
while (k1 - k0 > 1)
@@ -314,6 +324,11 @@ public static double Pwl(double arg, Point[] data)
314324
/// <returns>The interpolated value.</returns>
315325
public static double PwlDerivative(double arg, Point[] data)
316326
{
327+
if (arg <= data[0].X || arg >= data[data.Length - 1].X)
328+
{
329+
return 0.0;
330+
}
331+
317332
// Narrow in on the index for the piece-wise linear function
318333
int k0 = 0, k1 = data.Length;
319334
while (k1 - k0 > 1)

SpiceSharpBehavioral/SpiceSharpBehavioral.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373
<Version>4.7.0</Version>
7474
</PackageReference>
7575
</ItemGroup>
76-
</Project>
76+
</Project>

SpiceSharpBehavioralTest/Builders/BuilderTestData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static IEnumerable<TestCaseData> FunctionNodes
5757
yield return new TestCaseData(Node.Function("abs", Node.Add(Node.Multiply(Node.Minus(2.0), 6.0), 7.0)), 5.0).SetName("{m}(abs -2*6+7)");
5858
yield return new TestCaseData(Node.Function("min", Node.Minus(2.0), Node.Multiply(6.0, 2.0)), -2.0).SetName("{m}(min -2, 6*2)");
5959
yield return new TestCaseData(Node.Function("pwl", 2.0, 0.0, 1.0, 3.0, 4.0), 3.0).SetName("{m}(pwl 2,0,1,3,4)");
60+
yield return new TestCaseData(Node.Function("pwl", -1.0, 0.0, 1.0, 3.0, 4.0), 1.0).SetName("{m}(pwl -1,0,1,3,4)");
61+
yield return new TestCaseData(Node.Function("pwl", 4.0, 0.0, 1.0, 3.0, 4.0), 4.0).SetName("{m}(pwl 4,0,1,3,4)");
6062
yield return new TestCaseData(Node.Function("table", 2.0, 0.0, 1.0, 3.0, 4.0), 3.0).SetName("{m}(table 2,0,1,3,4)");
6163
yield return new TestCaseData(Node.Function("tbl", 2.0, 0.0, 1.0, 3.0, 4.0), 3.0).SetName("{m}(tbl 2,0,1,3,4)");
6264
yield return new TestCaseData(Node.Function("if", 1.0, 0.25, 0.75), 0.25).SetName("{m}(if 1 0.25 0.75)");

0 commit comments

Comments
 (0)