ref #65: new formula functions DELTA and GESTEP
This commit is contained in:
parent
3447cfecf2
commit
b0eb9ef807
53
calc.go
53
calc.go
|
@ -366,6 +366,7 @@ type formulaFuncs struct {
|
|||
// DEC2OCT
|
||||
// DECIMAL
|
||||
// DEGREES
|
||||
// DELTA
|
||||
// DEVSQ
|
||||
// DISC
|
||||
// DOLLARDE
|
||||
|
@ -392,6 +393,7 @@ type formulaFuncs struct {
|
|||
// GAMMALN
|
||||
// GCD
|
||||
// GEOMEAN
|
||||
// GESTEP
|
||||
// HARMEAN
|
||||
// HEX2BIN
|
||||
// HEX2DEC
|
||||
|
@ -1975,6 +1977,57 @@ func (fn *formulaFuncs) dec2x(name string, argsList *list.List) formulaArg {
|
|||
return newStringFormulaArg(strings.ToUpper(binary))
|
||||
}
|
||||
|
||||
// DELTA function tests two numbers for equality and returns the Kronecker
|
||||
// Delta. i.e. the function returns 1 if the two supplied numbers are equal
|
||||
// and 0 otherwise. The syntax of the function is:
|
||||
//
|
||||
// DELTA(number1,[number2])
|
||||
//
|
||||
func (fn *formulaFuncs) DELTA(argsList *list.List) formulaArg {
|
||||
if argsList.Len() < 1 {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "DELTA requires at least 1 argument")
|
||||
}
|
||||
if argsList.Len() > 2 {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "DELTA allows at most 2 arguments")
|
||||
}
|
||||
number1 := argsList.Front().Value.(formulaArg).ToNumber()
|
||||
if number1.Type != ArgNumber {
|
||||
return number1
|
||||
}
|
||||
number2 := newNumberFormulaArg(0)
|
||||
if argsList.Len() == 2 {
|
||||
if number2 = argsList.Back().Value.(formulaArg).ToNumber(); number2.Type != ArgNumber {
|
||||
return number2
|
||||
}
|
||||
}
|
||||
return newBoolFormulaArg(number1.Number == number2.Number).ToNumber()
|
||||
}
|
||||
|
||||
// GESTEP unction tests whether a supplied number is greater than a supplied
|
||||
// step size and returns. The syntax of the function is:
|
||||
//
|
||||
// GESTEP(number,[step])
|
||||
//
|
||||
func (fn *formulaFuncs) GESTEP(argsList *list.List) formulaArg {
|
||||
if argsList.Len() < 1 {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "GESTEP requires at least 1 argument")
|
||||
}
|
||||
if argsList.Len() > 2 {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "GESTEP allows at most 2 arguments")
|
||||
}
|
||||
number := argsList.Front().Value.(formulaArg).ToNumber()
|
||||
if number.Type != ArgNumber {
|
||||
return number
|
||||
}
|
||||
step := newNumberFormulaArg(0)
|
||||
if argsList.Len() == 2 {
|
||||
if step = argsList.Back().Value.(formulaArg).ToNumber(); step.Type != ArgNumber {
|
||||
return step
|
||||
}
|
||||
}
|
||||
return newBoolFormulaArg(number.Number >= step.Number).ToNumber()
|
||||
}
|
||||
|
||||
// HEX2BIN function converts a Hexadecimal (Base 16) number into a Binary
|
||||
// (Base 2) number. The syntax of the function is:
|
||||
//
|
||||
|
|
21
calc_test.go
21
calc_test.go
|
@ -137,6 +137,17 @@ func TestCalcCellValue(t *testing.T) {
|
|||
"=DEC2OCT(8,10)": "0000000010",
|
||||
"=DEC2OCT(-8)": "7777777770",
|
||||
"=DEC2OCT(237)": "355",
|
||||
// DELTA
|
||||
"=DELTA(5,4)": "0",
|
||||
"=DELTA(1.00001,1)": "0",
|
||||
"=DELTA(1.23,1.23)": "1",
|
||||
"=DELTA(1)": "0",
|
||||
"=DELTA(0)": "1",
|
||||
// GESTEP
|
||||
"=GESTEP(1.2,0.001)": "1",
|
||||
"=GESTEP(0.05,0.05)": "1",
|
||||
"=GESTEP(-0.00001,0)": "0",
|
||||
"=GESTEP(-0.00001)": "0",
|
||||
// HEX2BIN
|
||||
"=HEX2BIN(\"2\")": "10",
|
||||
"=HEX2BIN(\"0000000001\")": "1",
|
||||
|
@ -1562,6 +1573,16 @@ func TestCalcCellValue(t *testing.T) {
|
|||
"=DEC2OCT(-536870912 ,10)": "#NUM!",
|
||||
"=DEC2OCT(1,-1)": "#NUM!",
|
||||
"=DEC2OCT(8,1)": "#NUM!",
|
||||
// DELTA
|
||||
"=DELTA()": "DELTA requires at least 1 argument",
|
||||
"=DELTA(0,0,0)": "DELTA allows at most 2 arguments",
|
||||
"=DELTA(\"\",0)": "strconv.ParseFloat: parsing \"\": invalid syntax",
|
||||
"=DELTA(0,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
|
||||
// GESTEP
|
||||
"=GESTEP()": "GESTEP requires at least 1 argument",
|
||||
"=GESTEP(0,0,0)": "GESTEP allows at most 2 arguments",
|
||||
"=GESTEP(\"\",0)": "strconv.ParseFloat: parsing \"\": invalid syntax",
|
||||
"=GESTEP(0,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
|
||||
// HEX2BIN
|
||||
"=HEX2BIN()": "HEX2BIN requires at least 1 argument",
|
||||
"=HEX2BIN(1,1,1)": "HEX2BIN allows at most 2 arguments",
|
||||
|
|
Loading…
Reference in New Issue