Skip to content

Commit 9531cf1

Browse files
committed
Loving spreadsheet formulas
1 parent 6046fc9 commit 9531cf1

File tree

6 files changed

+663
-465
lines changed

6 files changed

+663
-465
lines changed

src/LO Basic/VBAExpressions.update.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<description xmlns="https://openoffice.org/extensions/update/2006"
33
xmlns:xlink="https://www.w3.org/1999/xlink">
44
<identifier value="com.ecpsolutions.extensions.vbaexpressions.oxt"/>
5-
<version value="1.0.8"/>
5+
<version value="1.0.9"/>
66
<update-download>
7-
<src xlink:href="https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.7/VBAExpressions.oxt"/>
7+
<src xlink:href="https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.8/VBAExpressions.oxt"/>
88
</update-download>
99
</description>

src/LO Basic/VBAExpressionsLib/TestRunner.xba

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ Sub RunAllTests
236236
&quot;ROUND(BETAINV(0.5;1;3);8)&quot;, _
237237
&quot;0.20629947&quot; _
238238
)
239+
Run( _
240+
&quot;Statistical Functions: BETA.DIST&quot;, _
241+
&quot;ROUND(BETA.DIST(2;8;10;False;1;3);7)&quot;, _
242+
&quot;1.4837646&quot; _
243+
)
239244
QRdec(&quot;Linear Algebra Functions: QR decomposition&quot;)
240245
Run( _
241246
&quot;Linear Algebra Functions: Cholesky&quot;, _

src/LO Basic/VBAExpressionsLib/VBAcallBack.xba

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ option ClassModule
3333
&apos;@--------------------------------------------------------------------
3434
&apos; Expose functions defined in the UDFunctions.cls
3535
Public UserDefFunctions As New UDFunctions
36-
Public SimpleMath As New clsSimpleMath
3736
</script:module>

src/LO Basic/VBAExpressionsLib/VBAexpressions.xba

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Private Sub Class_Initialize()
313313
AscDecSymbol = 46
314314
P_GALLOPING_MODE = True
315315
P_FORMATRESULT = False
316-
BuildinFunctIDList = &quot;abs;floor;achisq;asin;acos;aerf;afishf;agauss;asc;anorm;atn;astudt;array;avg&quot; &amp; _
316+
BuildinFunctIDList = &quot;abs;floor;achisq;asin;acos;aerf;afishf;agauss;asc;anorm;atn;astudt;array;avg;beta.dist&quot; &amp; _
317317
&quot;;betainv;ceil;chisq;cholesky;cholinverse;cholsolve;chr;cos;choose;date;dateadd;datediff&quot; &amp; _
318318
&quot;;datepart;dateserial;datevalue;day;ddb;det;erf;exp;fishf;fit;format;fv;fzero&quot; &amp; _
319319
&quot;;gamma;gammaln;gauss;get;hour;ibeta;iff;inverse;ipmt;irr;lcase;left;len;log;lgn&quot; &amp; _
@@ -323,7 +323,7 @@ Private Sub Class_Initialize()
323323
&quot;;syd;tan;timeserial;timevalue;tinv;tinv_1t;tinv_2t;trim;ucase;weekday&quot; &amp; _
324324
&quot;;weekdayname;year&quot;
325325
BuildinFunctNameList = &quot;Absolute;aFloor;ACHISQ;ArcSin;ArcCos;AERF;AFISHF;AGAUSS;ASCII;ANORM;ArcTan&quot; &amp; _
326-
&quot;;ASTUDT;strArray;Average;BETAINV;aCeiling;CHISQ;CholeskyDec;CholeskyInverseMatrix&quot; &amp; _
326+
&quot;;ASTUDT;strArray;Average;Beta_Distribution;BETAINV;aCeiling;CHISQ;CholeskyDec;CholeskyInverseMatrix&quot; &amp; _
327327
&quot;;CholeskySolve;ASCIIchr;Cosin;aChoose;aDate;aDateAdd;aDateDiff;aDatePart;aDateSerial&quot; &amp; _
328328
&quot;;aDateValue;aDay;aDDB;MatrixDeterminant;ERF;ExpEuler;FISHF;CurveFit&quot; &amp; _
329329
&quot;;aFormat;aFV;FunctionZero;Gamma;GammaLN;GAUSS;GET;aHour;iBETA;aIff;InverseMatrix&quot; &amp; _
@@ -1537,6 +1537,102 @@ Private Function BETAINV_(p As Double, A As Double, B As Double) As Double
15371537
BETAINV_ = x
15381538
End Function
15391539

1540+
&apos;&apos;&apos; &lt;summary&gt;
1541+
&apos;&apos;&apos; Returns the beta distribution.
1542+
&apos;&apos;&apos; &lt;/summary&gt;
1543+
&apos;&apos;&apos; &lt;param name=&quot;x&quot;&gt;The value between A and B at which to evaluate the function.&lt;/param&gt;
1544+
&apos;&apos;&apos; &lt;param name=&quot;alpha&quot;&gt;Shape parameter alpha.&lt;/param&gt;
1545+
&apos;&apos;&apos; &lt;param name=&quot;beta&quot;&gt;Shape parameter beta.&lt;/param&gt;
1546+
&apos;&apos;&apos; &lt;param name=&quot;Cumulative&quot;&gt;
1547+
&apos;&apos;&apos; A logical value that determines the form of the function. If cumulative is TRUE,
1548+
&apos;&apos;&apos; BETADIST returns the cumulative distribution function; if FALSE, it returns
1549+
&apos;&apos;&apos; the probability density function (PDF).
1550+
&apos;&apos;&apos; &lt;/param&gt;
1551+
&apos;&apos;&apos; &lt;param name=&quot;A&quot;&gt;Optional. A lower bound to the interval of x.&lt;/param&gt;
1552+
&apos;&apos;&apos; &lt;param name=&quot;B&quot;&gt;Optional. An upper bound to the interval of x.&lt;/param&gt;
1553+
Private Function BETADIST(ByRef expression As String, ByRef fName As String) As String
1554+
Dim argsCount As Long
1555+
Dim tmpData() As String
1556+
Dim tmpEval As String
1557+
Dim LB As Long, UB As Long
1558+
1559+
On Error GoTo err_Handler
1560+
tmpData() = SplitArgs(expression)
1561+
LB = LBound(tmpData)
1562+
UB = UBound(tmpData)
1563+
argsCount = UB - LB + 1
1564+
Select Case argsCount
1565+
Case 4
1566+
tmpEval = BETAPDF_EXCEL( _
1567+
CDbl(tmpData(LB)), _
1568+
CDbl(tmpData(LB + 1)), _
1569+
CDbl(tmpData(LB + 2)), _
1570+
CBool(tmpData(LB + 3)), _
1571+
0, 1)
1572+
Case 6
1573+
tmpEval = BETAPDF_EXCEL( _
1574+
CDbl(tmpData(LB)), _
1575+
CDbl(tmpData(LB + 1)), _
1576+
CDbl(tmpData(LB + 2)), _
1577+
CBool(tmpData(LB + 3)), _
1578+
CDbl(tmpData(LB + 4)), _
1579+
CDbl(tmpData(UB)))
1580+
Case Else
1581+
tmpEval = e_ValueError
1582+
BuildErrMessage errMissingArgsOrTooManyArgs, d_lCurly &amp; fName &amp; d_rCurly
1583+
End Select
1584+
BETADIST = tmpEval: Erase tmpData
1585+
Exit Function
1586+
err_Handler:
1587+
BETADIST = e_ValueError
1588+
BuildErrMessage errEvalError, d_lCurly &amp; fName &amp; d_rCurly &amp; &quot; | Error#: &quot; &amp; err.Number &amp; d_Space &amp; _
1589+
d_lParenthesis &amp; err.Description &amp; d_rParenthesis
1590+
End Function
1591+
1592+
Private Function BETALN_(x As Double, y As Double) As Double
1593+
BETALN_ = GAMMALN_(x) + GAMMALN_(y) - GAMMALN_(x + y)
1594+
End Function
1595+
1596+
Private Function BETAPDF_(x As Double, Alpha As Double, Beta As Double) As Double
1597+
BETAPDF_ = Exp((Alpha - 1) * Log(x) + (Beta - 1) * Log(1 - x) - BETALN_(Alpha, Beta))
1598+
End Function
1599+
1600+
Private Function BETAPDF_EXCEL(x As Double, Alpha As Double, _
1601+
Beta As Double, Cumulative As Boolean, _
1602+
Lower_Bound As Double, _
1603+
Upper_Bound As Double) As Variant
1604+
Dim z As Double
1605+
Dim range_ As Double
1606+
1607+
If Upper_Bound &gt; Lower_Bound Then
1608+
If x &gt; Lower_Bound And x &lt; Upper_Bound Then
1609+
range_ = (Upper_Bound - Lower_Bound)
1610+
z = (x - Lower_Bound) / range_
1611+
If Cumulative Then
1612+
BETAPDF_EXCEL = iBETA_(z, Alpha, Beta)
1613+
Else
1614+
BETAPDF_EXCEL = BETAPDF_(z, Alpha, Beta) / range_
1615+
End If
1616+
Else
1617+
If x = Lower_Bound Or x = Upper_Bound Then
1618+
If Cumulative Then
1619+
If x = Upper_Bound Then
1620+
BETAPDF_EXCEL = 1
1621+
Else
1622+
BETAPDF_EXCEL = 0
1623+
End If
1624+
Else
1625+
BETAPDF_EXCEL = 0
1626+
End If
1627+
Else
1628+
BETAPDF_EXCEL = &quot;#NUM!&quot;
1629+
End If
1630+
End If
1631+
Else
1632+
BETAPDF_EXCEL = &quot;#NUM!&quot;
1633+
End If
1634+
End Function
1635+
15401636
Private Sub BottomLevelEval(ByRef aToken As token)
15411637
On Error GoTo BLevelEval_errHanlder
15421638
If aToken.OperationToken &lt; 100 Then &apos;Arithmetic operators
@@ -2728,6 +2824,8 @@ Private Function EvalFunction(ByRef Argument As String, ByRef FunctionName As St
27282824
EvalFunction = Asc_(Argument, FunctionName)
27292825
Case &quot;Average&quot;
27302826
EvalFunction = average(Argument, FunctionName)
2827+
Case &quot;Beta_Distribution&quot;
2828+
EvalFunction = BETADIST(Argument, FunctionName)
27312829
Case &quot;BETAINV&quot;
27322830
EvalFunction = BETAINV(Argument, FunctionName)
27332831
Case &quot;Cosin&quot;

src/LO Basic/release-notes_en.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A note on!
2-
## Bug Fix
3-
- [x] Resolved error when parsing literal strings with reserved grammar tokens.
1+
# Loving spreadsheet formulas!
2+
## New Functions
3+
- [x] Added Excel `BETA.DIST` for the cumulative distribution function (CDF) and the probabilistic distribution function (PDF) of the Beta distribution.
44

55
## Download
6-
https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.7/VBAExpressions.oxt
6+
https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.8/VBAExpressions.oxt

0 commit comments

Comments
 (0)