From 441ae741d7eaca24e677f553456f9b0c6a9efcda Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 5 Sep 2022 06:36:42 +0200 Subject: [PATCH] Update Excel function samples for Date/Time and Engineering functions --- samples/Calculations/DateTime/DATEDIF.php | 1 + samples/Calculations/DateTime/DAYS.php | 1 + samples/Calculations/DateTime/NETWORKDAYS.php | 66 ++++++++++++++++ samples/Calculations/DateTime/WORKDAY.php | 67 ++++++++++++++++ samples/Calculations/DateTime/YEARFRAC.php | 76 +++++++++++++++++++ samples/Calculations/Engineering/BESSELI.php | 29 +++++++ samples/Calculations/Engineering/BESSELJ.php | 29 +++++++ samples/Calculations/Engineering/BESSELK.php | 29 +++++++ samples/Calculations/Engineering/BESSELY.php | 29 +++++++ samples/Calculations/Engineering/BIN2DEC.php | 46 +++++++++++ samples/Calculations/Engineering/BIN2HEX.php | 46 +++++++++++ samples/Calculations/Engineering/BIN2OCT.php | 46 +++++++++++ samples/Calculations/Engineering/BITAND.php | 49 ++++++++++++ .../Calculations/Engineering/BITLSHIFT.php | 65 ++++++++++++++++ samples/Calculations/Engineering/BITOR.php | 49 ++++++++++++ .../Calculations/Engineering/BITRSHIFT.php | 63 +++++++++++++++ samples/Calculations/Engineering/BITXOR.php | 49 ++++++++++++ samples/Calculations/Engineering/COMPLEX.php | 41 ++++++++++ samples/Calculations/Engineering/CONVERT.php | 58 ++++++++++++++ samples/Calculations/Engineering/DEC2BIN.php | 47 ++++++++++++ samples/Calculations/Engineering/DEC2HEX.php | 48 ++++++++++++ samples/Calculations/Engineering/DEC2OCT.php | 48 ++++++++++++ samples/Calculations/Engineering/DELTA.php | 46 +++++++++++ samples/Calculations/Engineering/ERF.php | 67 ++++++++++++++++ samples/Calculations/Engineering/ERFC.php | 41 ++++++++++ samples/Calculations/Engineering/GESTEP.php | 53 +++++++++++++ samples/Calculations/Engineering/HEX2BIN.php | 46 +++++++++++ samples/Calculations/Engineering/HEX2DEC.php | 48 ++++++++++++ samples/Calculations/Engineering/HEX2OCT.php | 46 +++++++++++ samples/Calculations/Engineering/IMABS.php | 48 ++++++++++++ .../Calculations/Engineering/IMAGINARY.php | 48 ++++++++++++ .../Calculations/Engineering/IMARGUMENT.php | 48 ++++++++++++ .../Calculations/Engineering/IMCONJUGATE.php | 48 ++++++++++++ samples/Calculations/Engineering/IMCOS.php | 48 ++++++++++++ samples/Calculations/Engineering/IMCOSH.php | 48 ++++++++++++ samples/Calculations/Engineering/IMCOT.php | 48 ++++++++++++ samples/Calculations/Engineering/IMCSC.php | 48 ++++++++++++ samples/Calculations/Engineering/IMCSCH.php | 48 ++++++++++++ samples/Calculations/Engineering/IMDIV.php | 42 ++++++++++ samples/Calculations/Engineering/IMEXP.php | 48 ++++++++++++ samples/Calculations/Engineering/IMLN.php | 48 ++++++++++++ samples/Calculations/Engineering/IMLOG10.php | 48 ++++++++++++ samples/Calculations/Engineering/IMLOG2.php | 48 ++++++++++++ samples/Calculations/Engineering/IMPOWER.php | 49 ++++++++++++ .../Calculations/Engineering/IMPRODUCT.php | 42 ++++++++++ samples/Calculations/Engineering/IMREAL.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSEC.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSECH.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSIN.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSINH.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSQRT.php | 48 ++++++++++++ samples/Calculations/Engineering/IMSUB.php | 42 ++++++++++ samples/Calculations/Engineering/IMSUM.php | 42 ++++++++++ samples/Calculations/Engineering/IMTAN.php | 48 ++++++++++++ samples/Calculations/Engineering/OCT2BIN.php | 47 ++++++++++++ samples/Calculations/Engineering/OCT2DEC.php | 49 ++++++++++++ samples/Calculations/Engineering/OCT2HEX.php | 49 ++++++++++++ .../Calculation/Engineering/Compare.php | 4 +- tests/data/Calculation/DateTime/DATE.php | 5 +- .../data/Calculation/Engineering/BIN2DEC.php | 2 + 60 files changed, 2659 insertions(+), 3 deletions(-) create mode 100644 samples/Calculations/DateTime/NETWORKDAYS.php create mode 100644 samples/Calculations/DateTime/WORKDAY.php create mode 100644 samples/Calculations/DateTime/YEARFRAC.php create mode 100644 samples/Calculations/Engineering/BESSELI.php create mode 100644 samples/Calculations/Engineering/BESSELJ.php create mode 100644 samples/Calculations/Engineering/BESSELK.php create mode 100644 samples/Calculations/Engineering/BESSELY.php create mode 100644 samples/Calculations/Engineering/BIN2DEC.php create mode 100644 samples/Calculations/Engineering/BIN2HEX.php create mode 100644 samples/Calculations/Engineering/BIN2OCT.php create mode 100644 samples/Calculations/Engineering/BITAND.php create mode 100644 samples/Calculations/Engineering/BITLSHIFT.php create mode 100644 samples/Calculations/Engineering/BITOR.php create mode 100644 samples/Calculations/Engineering/BITRSHIFT.php create mode 100644 samples/Calculations/Engineering/BITXOR.php create mode 100644 samples/Calculations/Engineering/COMPLEX.php create mode 100644 samples/Calculations/Engineering/CONVERT.php create mode 100644 samples/Calculations/Engineering/DEC2BIN.php create mode 100644 samples/Calculations/Engineering/DEC2HEX.php create mode 100644 samples/Calculations/Engineering/DEC2OCT.php create mode 100644 samples/Calculations/Engineering/DELTA.php create mode 100644 samples/Calculations/Engineering/ERF.php create mode 100644 samples/Calculations/Engineering/ERFC.php create mode 100644 samples/Calculations/Engineering/GESTEP.php create mode 100644 samples/Calculations/Engineering/HEX2BIN.php create mode 100644 samples/Calculations/Engineering/HEX2DEC.php create mode 100644 samples/Calculations/Engineering/HEX2OCT.php create mode 100644 samples/Calculations/Engineering/IMABS.php create mode 100644 samples/Calculations/Engineering/IMAGINARY.php create mode 100644 samples/Calculations/Engineering/IMARGUMENT.php create mode 100644 samples/Calculations/Engineering/IMCONJUGATE.php create mode 100644 samples/Calculations/Engineering/IMCOS.php create mode 100644 samples/Calculations/Engineering/IMCOSH.php create mode 100644 samples/Calculations/Engineering/IMCOT.php create mode 100644 samples/Calculations/Engineering/IMCSC.php create mode 100644 samples/Calculations/Engineering/IMCSCH.php create mode 100644 samples/Calculations/Engineering/IMDIV.php create mode 100644 samples/Calculations/Engineering/IMEXP.php create mode 100644 samples/Calculations/Engineering/IMLN.php create mode 100644 samples/Calculations/Engineering/IMLOG10.php create mode 100644 samples/Calculations/Engineering/IMLOG2.php create mode 100644 samples/Calculations/Engineering/IMPOWER.php create mode 100644 samples/Calculations/Engineering/IMPRODUCT.php create mode 100644 samples/Calculations/Engineering/IMREAL.php create mode 100644 samples/Calculations/Engineering/IMSEC.php create mode 100644 samples/Calculations/Engineering/IMSECH.php create mode 100644 samples/Calculations/Engineering/IMSIN.php create mode 100644 samples/Calculations/Engineering/IMSINH.php create mode 100644 samples/Calculations/Engineering/IMSQRT.php create mode 100644 samples/Calculations/Engineering/IMSUB.php create mode 100644 samples/Calculations/Engineering/IMSUM.php create mode 100644 samples/Calculations/Engineering/IMTAN.php create mode 100644 samples/Calculations/Engineering/OCT2BIN.php create mode 100644 samples/Calculations/Engineering/OCT2DEC.php create mode 100644 samples/Calculations/Engineering/OCT2HEX.php diff --git a/samples/Calculations/DateTime/DATEDIF.php b/samples/Calculations/DateTime/DATEDIF.php index 7bc077c9..3e035f5a 100644 --- a/samples/Calculations/DateTime/DATEDIF.php +++ b/samples/Calculations/DateTime/DATEDIF.php @@ -24,6 +24,7 @@ $testDates = [ [2000, 1, 1], [2019, 2, 14], [2020, 7, 4], + [2020, 2, 29], ]; $testDateCount = count($testDates); diff --git a/samples/Calculations/DateTime/DAYS.php b/samples/Calculations/DateTime/DAYS.php index ddd47f37..15e9a58f 100644 --- a/samples/Calculations/DateTime/DAYS.php +++ b/samples/Calculations/DateTime/DAYS.php @@ -24,6 +24,7 @@ $testDates = [ [2000, 1, 1], [2019, 2, 14], [2020, 7, 4], + [2020, 2, 29], [2029, 12, 31], [2525, 1, 1], ]; diff --git a/samples/Calculations/DateTime/NETWORKDAYS.php b/samples/Calculations/DateTime/NETWORKDAYS.php new file mode 100644 index 00000000..585c0438 --- /dev/null +++ b/samples/Calculations/DateTime/NETWORKDAYS.php @@ -0,0 +1,66 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$publicHolidays = [ + [2022, 1, 3, '=DATE(G1, H1, I1)', 'New Year'], + [2022, 4, 15, '=DATE(G2, H2, I2)', 'Good Friday'], + [2022, 4, 18, '=DATE(G3, H3, I3)', 'Easter Monday'], + [2022, 5, 2, '=DATE(G4, H4, I4)', 'Early May Bank Holiday'], + [2022, 6, 2, '=DATE(G5, H5, I5)', 'Spring Bank Holiday'], + [2022, 6, 3, '=DATE(G6, H6, I6)', 'Platinum Jubilee Bank Holiday'], + [2022, 8, 29, '=DATE(G7, H7, I7)', 'Summer Bank Holiday'], + [2022, 12, 26, '=DATE(G8, H8, I8)', 'Boxing Day'], + [2022, 12, 27, '=DATE(G9, H9, I9)', 'Christmas Day'], +]; + +$holidayCount = count($publicHolidays); +$worksheet->fromArray($publicHolidays, null, 'G1', true); + +$worksheet->getStyle('J1:J' . $holidayCount) + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +$worksheet->setCellValue('A1', '=DATE(2022,1,1)'); + +for ($numberOfMonths = 0; $numberOfMonths < 12; ++$numberOfMonths) { + $worksheet->setCellValue('B' . ($numberOfMonths + 1), '=EOMONTH(A1, ' . $numberOfMonths . ')'); + $worksheet->setCellValue('C' . ($numberOfMonths + 1), '=NETWORKDAYS(A1, B' . ($numberOfMonths + 1) . ')'); + $worksheet->setCellValue('D' . ($numberOfMonths + 1), '=NETWORKDAYS(A1, B' . ($numberOfMonths + 1) . ', J1:J' . $holidayCount . ')'); +} + +$worksheet->getStyle('A1') + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +$worksheet->getStyle('B1:B12') + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +// Test the formulae +$helper->log('UK Public Holidays'); +$holidayData = $worksheet->rangeToArray('J1:K' . $holidayCount, null, true, true, true); +$helper->displayGrid($holidayData); + +for ($row = 1; $row <= 12; ++$row) { + $helper->log(sprintf( + 'Between %s and %s is %d working days; %d with public holidays', + $worksheet->getCell('A1')->getFormattedValue(), + $worksheet->getCell('B' . $row)->getFormattedValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue() + )); +} diff --git a/samples/Calculations/DateTime/WORKDAY.php b/samples/Calculations/DateTime/WORKDAY.php new file mode 100644 index 00000000..d18e3463 --- /dev/null +++ b/samples/Calculations/DateTime/WORKDAY.php @@ -0,0 +1,67 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$publicHolidays = [ + [2022, 1, 3, '=DATE(G1, H1, I1)', 'New Year'], + [2022, 4, 15, '=DATE(G2, H2, I2)', 'Good Friday'], + [2022, 4, 18, '=DATE(G3, H3, I3)', 'Easter Monday'], + [2022, 5, 2, '=DATE(G4, H4, I4)', 'Early May Bank Holiday'], + [2022, 6, 2, '=DATE(G5, H5, I5)', 'Spring Bank Holiday'], + [2022, 6, 3, '=DATE(G6, H6, I6)', 'Platinum Jubilee Bank Holiday'], + [2022, 8, 29, '=DATE(G7, H7, I7)', 'Summer Bank Holiday'], + [2022, 12, 26, '=DATE(G8, H8, I8)', 'Boxing Day'], + [2022, 12, 27, '=DATE(G9, H9, I9)', 'Christmas Day'], +]; + +$holidayCount = count($publicHolidays); +$worksheet->fromArray($publicHolidays, null, 'G1', true); + +$worksheet->getStyle('J1:J' . $holidayCount) + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +$worksheet->setCellValue('A1', '=DATE(2022,1,1)'); + +$workdayStep = 10; +for ($days = $workdayStep; $days <= 366; $days += $workdayStep) { + $worksheet->setCellValue('B' . ((int) $days / $workdayStep + 1), $days); + $worksheet->setCellValue('C' . ((int) $days / $workdayStep + 1), '=WORKDAY(A1, B' . ((int) $days / $workdayStep + 1) . ')'); + $worksheet->setCellValue('D' . ((int) $days / $workdayStep + 1), '=WORKDAY(A1, B' . ((int) $days / $workdayStep + 1) . ', J1:J' . $holidayCount . ')'); +} + +$worksheet->getStyle('A1') + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +$worksheet->getStyle('C1:D50') + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +// Test the formulae +$helper->log('UK Public Holidays'); +$holidayData = $worksheet->rangeToArray('J1:K' . $holidayCount, null, true, true, true); +$helper->displayGrid($holidayData); + +for ($days = $workdayStep; $days <= 366; $days += $workdayStep) { + $helper->log(sprintf( + '%d workdays from %s is %s; %s with public holidays', + $worksheet->getCell('B' . ((int) $days / $workdayStep + 1))->getFormattedValue(), + $worksheet->getCell('A1')->getFormattedValue(), + $worksheet->getCell('C' . ((int) $days / $workdayStep + 1))->getFormattedValue(), + $worksheet->getCell('D' . ((int) $days / $workdayStep + 1))->getFormattedValue() + )); +} diff --git a/samples/Calculations/DateTime/YEARFRAC.php b/samples/Calculations/DateTime/YEARFRAC.php new file mode 100644 index 00000000..81b36435 --- /dev/null +++ b/samples/Calculations/DateTime/YEARFRAC.php @@ -0,0 +1,76 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testDates = [ + [1900, 1, 1], + [1904, 1, 1], + [1936, 3, 17], + [1960, 12, 19], + [1999, 12, 31], + [2000, 1, 1], + [2019, 2, 14], + [2020, 7, 4], + [2020, 2, 29], + [2029, 12, 31], + [2525, 1, 1], +]; +$testDateCount = count($testDates); + +$worksheet->fromArray($testDates, null, 'A1', true); + +for ($row = 1; $row <= $testDateCount; ++$row) { + $worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')'); + $worksheet->setCellValue('E' . $row, '=D' . $row); + $worksheet->setCellValue('F' . $row, '=DATE(2022,12,31)'); + $worksheet->setCellValue('G' . $row, '=YEARFRAC(D' . $row . ', F' . $row . ')'); + $worksheet->setCellValue('H' . $row, '=YEARFRAC(D' . $row . ', F' . $row . ', 1)'); + $worksheet->setCellValue('I' . $row, '=YEARFRAC(D' . $row . ', F' . $row . ', 2)'); + $worksheet->setCellValue('J' . $row, '=YEARFRAC(D' . $row . ', F' . $row . ', 3)'); + $worksheet->setCellValue('K' . $row, '=YEARFRAC(D' . $row . ', F' . $row . ', 4)'); +} +$worksheet->getStyle('E1:F' . $testDateCount) + ->getNumberFormat() + ->setFormatCode('yyyy-mm-dd'); + +// Test the formulae +for ($row = 1; $row <= $testDateCount; ++$row) { + $helper->log(sprintf( + 'Between: %s and %s', + $worksheet->getCell('E' . $row)->getFormattedValue(), + $worksheet->getCell('F' . $row)->getFormattedValue() + )); + $helper->log(sprintf( + 'Days: %f - US (NASD) 30/360', + $worksheet->getCell('G' . $row)->getCalculatedValue() + )); + $helper->log(sprintf( + 'Days: %f - Actual', + $worksheet->getCell('H' . $row)->getCalculatedValue() + )); + $helper->log(sprintf( + 'Days: %f - Actual/360', + $worksheet->getCell('I' . $row)->getCalculatedValue() + )); + $helper->log(sprintf( + 'Days: %f - Actual/365', + $worksheet->getCell('J' . $row)->getCalculatedValue() + )); + $helper->log(sprintf( + 'Days: %f - European 30/360', + $worksheet->getCell('K' . $row)->getCalculatedValue() + )); +} diff --git a/samples/Calculations/Engineering/BESSELI.php b/samples/Calculations/Engineering/BESSELI.php new file mode 100644 index 00000000..bd5d9b71 --- /dev/null +++ b/samples/Calculations/Engineering/BESSELI.php @@ -0,0 +1,29 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +for ($n = 0; $n <= 5; ++$n) { + for ($x = 0; $x <= 5; $x = $x + 0.25) { + Calculation::getInstance($spreadsheet)->flushInstance(); + $worksheet->setCellValue('A1', "=BESSELI({$x}, {$n})"); + + $helper->log(sprintf( + '%s = %f', + $worksheet->getCell('A1')->getValue(), + $worksheet->getCell('A1')->getCalculatedValue() + )); + } +} diff --git a/samples/Calculations/Engineering/BESSELJ.php b/samples/Calculations/Engineering/BESSELJ.php new file mode 100644 index 00000000..3aa47886 --- /dev/null +++ b/samples/Calculations/Engineering/BESSELJ.php @@ -0,0 +1,29 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +for ($n = 0; $n <= 5; ++$n) { + for ($x = 0; $x <= 5; $x = $x + 0.25) { + Calculation::getInstance($spreadsheet)->flushInstance(); + $worksheet->setCellValue('A1', "=BESSELJ({$x}, {$n})"); + + $helper->log(sprintf( + '%s = %f', + $worksheet->getCell('A1')->getValue(), + $worksheet->getCell('A1')->getCalculatedValue() + )); + } +} diff --git a/samples/Calculations/Engineering/BESSELK.php b/samples/Calculations/Engineering/BESSELK.php new file mode 100644 index 00000000..ee8698e9 --- /dev/null +++ b/samples/Calculations/Engineering/BESSELK.php @@ -0,0 +1,29 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +for ($n = 0; $n <= 5; ++$n) { + for ($x = 0; $x <= 5; $x = $x + 0.25) { + Calculation::getInstance($spreadsheet)->flushInstance(); + $worksheet->setCellValue('A1', "=BESSELK({$x}, {$n})"); + + $helper->log(sprintf( + '%s = %f', + $worksheet->getCell('A1')->getValue(), + $worksheet->getCell('A1')->getCalculatedValue() + )); + } +} diff --git a/samples/Calculations/Engineering/BESSELY.php b/samples/Calculations/Engineering/BESSELY.php new file mode 100644 index 00000000..750b7204 --- /dev/null +++ b/samples/Calculations/Engineering/BESSELY.php @@ -0,0 +1,29 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +for ($n = 0; $n <= 5; ++$n) { + for ($x = 0; $x <= 5; $x = $x + 0.25) { + Calculation::getInstance($spreadsheet)->flushInstance(); + $worksheet->setCellValue('A1', "=BESSELY({$x}, {$n})"); + + $helper->log(sprintf( + '%s = %f', + $worksheet->getCell('A1')->getValue(), + $worksheet->getCell('A1')->getCalculatedValue() + )); + } +} diff --git a/samples/Calculations/Engineering/BIN2DEC.php b/samples/Calculations/Engineering/BIN2DEC.php new file mode 100644 index 00000000..0c4c4532 --- /dev/null +++ b/samples/Calculations/Engineering/BIN2DEC.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [101], + [110110], + [1000000], + [11111111], + [100010101], + [110001100], + [111111111], + [1111111111], + [1100110011], + [1000000000], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=BIN2DEC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Binary %s is decimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BIN2HEX.php b/samples/Calculations/Engineering/BIN2HEX.php new file mode 100644 index 00000000..51a11199 --- /dev/null +++ b/samples/Calculations/Engineering/BIN2HEX.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [101], + [110110], + [1000000], + [11111111], + [100010101], + [110001100], + [111111111], + [1111111111], + [1100110011], + [1000000000], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=BIN2HEX(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Binary %s is hexadecimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BIN2OCT.php b/samples/Calculations/Engineering/BIN2OCT.php new file mode 100644 index 00000000..c320d360 --- /dev/null +++ b/samples/Calculations/Engineering/BIN2OCT.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [101], + [110110], + [1000000], + [11111111], + [100010101], + [110001100], + [111111111], + [1111111111], + [1100110011], + [1000000000], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=BIN2OCT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Binary %s is octal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BITAND.php b/samples/Calculations/Engineering/BITAND.php new file mode 100644 index 00000000..2a8f7a3c --- /dev/null +++ b/samples/Calculations/Engineering/BITAND.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [1, 5], + [3, 5], + [1, 6], + [9, 6], + [13, 25], + [23, 10], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=TEXT(DEC2BIN(A' . $row . '), "00000")'); + $worksheet->setCellValue('D' . $row, '=TEXT(DEC2BIN(B' . $row . '), "00000")'); + $worksheet->setCellValue('E' . $row, '=BITAND(A' . $row . ',B' . $row . ')'); + $worksheet->setCellValue('F' . $row, '=TEXT(DEC2BIN(E' . $row . '), "00000")'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Bitwise AND of %d (%s) and %d (%s) is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + $worksheet->getCell('E' . $row)->getCalculatedValue(), + $worksheet->getCell('F' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BITLSHIFT.php b/samples/Calculations/Engineering/BITLSHIFT.php new file mode 100644 index 00000000..872c8098 --- /dev/null +++ b/samples/Calculations/Engineering/BITLSHIFT.php @@ -0,0 +1,65 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [1], + [3], + [9], + [15], + [26], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=DEC2BIN(A' . $row . ')'); + $worksheet->setCellValue('C' . $row, '=BITLSHIFT(A' . $row . ',1)'); + $worksheet->setCellValue('D' . $row, '=DEC2BIN(C' . $row . ')'); + $worksheet->setCellValue('E' . $row, '=BITLSHIFT(A' . $row . ',2)'); + $worksheet->setCellValue('F' . $row, '=DEC2BIN(E' . $row . ')'); + $worksheet->setCellValue('G' . $row, '=BITLSHIFT(A' . $row . ',3)'); + $worksheet->setCellValue('H' . $row, '=DEC2BIN(G' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Bitwise Left Shift of %d (%s) by 1 bit is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + )); + $helper->log(sprintf( + '(E%d): Bitwise Left Shift of %d (%s) by 2 bits is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('E' . $row)->getCalculatedValue(), + $worksheet->getCell('F' . $row)->getCalculatedValue(), + )); + $helper->log(sprintf( + '(E%d): Bitwise Left Shift of %d (%s) by 3 bits is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('G' . $row)->getCalculatedValue(), + $worksheet->getCell('H' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BITOR.php b/samples/Calculations/Engineering/BITOR.php new file mode 100644 index 00000000..1bf7f71d --- /dev/null +++ b/samples/Calculations/Engineering/BITOR.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [1, 5], + [3, 5], + [1, 6], + [9, 6], + [13, 25], + [23, 10], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=TEXT(DEC2BIN(A' . $row . '), "00000")'); + $worksheet->setCellValue('D' . $row, '=TEXT(DEC2BIN(B' . $row . '), "00000")'); + $worksheet->setCellValue('E' . $row, '=BITOR(A' . $row . ',B' . $row . ')'); + $worksheet->setCellValue('F' . $row, '=TEXT(DEC2BIN(E' . $row . '), "00000")'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Bitwise OR of %d (%s) and %d (%s) is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + $worksheet->getCell('E' . $row)->getCalculatedValue(), + $worksheet->getCell('F' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BITRSHIFT.php b/samples/Calculations/Engineering/BITRSHIFT.php new file mode 100644 index 00000000..3e7f3a88 --- /dev/null +++ b/samples/Calculations/Engineering/BITRSHIFT.php @@ -0,0 +1,63 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [9], + [15], + [26], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=DEC2BIN(A' . $row . ')'); + $worksheet->setCellValue('C' . $row, '=BITRSHIFT(A' . $row . ',1)'); + $worksheet->setCellValue('D' . $row, '=DEC2BIN(C' . $row . ')'); + $worksheet->setCellValue('E' . $row, '=BITRSHIFT(A' . $row . ',2)'); + $worksheet->setCellValue('F' . $row, '=DEC2BIN(E' . $row . ')'); + $worksheet->setCellValue('G' . $row, '=BITRSHIFT(A' . $row . ',3)'); + $worksheet->setCellValue('H' . $row, '=DEC2BIN(G' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Bitwise Right Shift of %d (%s) by 1 bit is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + )); + $helper->log(sprintf( + '(E%d): Bitwise Right Shift of %d (%s) by 2 bits is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('E' . $row)->getCalculatedValue(), + $worksheet->getCell('F' . $row)->getCalculatedValue(), + )); + $helper->log(sprintf( + '(E%d): Bitwise Right Shift of %d (%s) by 3 bits is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + $worksheet->getCell('G' . $row)->getCalculatedValue(), + $worksheet->getCell('H' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/BITXOR.php b/samples/Calculations/Engineering/BITXOR.php new file mode 100644 index 00000000..482662cd --- /dev/null +++ b/samples/Calculations/Engineering/BITXOR.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [1, 5], + [3, 5], + [1, 6], + [9, 6], + [13, 25], + [23, 10], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=TEXT(DEC2BIN(A' . $row . '), "00000")'); + $worksheet->setCellValue('D' . $row, '=TEXT(DEC2BIN(B' . $row . '), "00000")'); + $worksheet->setCellValue('E' . $row, '=BITXOR(A' . $row . ',B' . $row . ')'); + $worksheet->setCellValue('F' . $row, '=TEXT(DEC2BIN(E' . $row . '), "00000")'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Bitwise XOR of %d (%s) and %d (%s) is %d (%s)', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + $worksheet->getCell('E' . $row)->getCalculatedValue(), + $worksheet->getCell('F' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/COMPLEX.php b/samples/Calculations/Engineering/COMPLEX.php new file mode 100644 index 00000000..c58a1797 --- /dev/null +++ b/samples/Calculations/Engineering/COMPLEX.php @@ -0,0 +1,41 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [3, 4], + [3, 4, '"j"'], + [3.5, 4.75], + [0, 1], + [1, 0], + [0, -1], + [0, 2], + [2, 0], +]; +$testDataCount = count($testData); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('A' . $row, '=COMPLEX(' . implode(',', $testData[$row - 1]) . ')'); +} + +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(A%d): Formula %s result is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('A' . $row)->getCalculatedValue() + )); +} diff --git a/samples/Calculations/Engineering/CONVERT.php b/samples/Calculations/Engineering/CONVERT.php new file mode 100644 index 00000000..bce56ba5 --- /dev/null +++ b/samples/Calculations/Engineering/CONVERT.php @@ -0,0 +1,58 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$conversions = [ + [1, '"lbm"', '"kg"'], + [1, '"gal"', '"l"'], + [24, '"in"', '"ft"'], + [100, '"yd"', '"m"'], + [500, '"mi"', '"km"'], + [7.5, '"min"', '"sec"'], + [5, '"F"', '"C"'], + [32, '"C"', '"K"'], + [100, '"m2"', '"ft2"'], +]; +$testDataCount = count($conversions); + +$worksheet->fromArray($conversions, null, 'A1'); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('D' . $row, '=CONVERT(' . implode(',', $conversions[$row - 1]) . ')'); +} + +$worksheet->setCellValue('H1', '=CONVERT(CONVERT(100,"m","ft"),"m","ft")'); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(A%d): Unit of Measure Conversion Formula %s - %d %s is %f %s', + $row, + $worksheet->getCell('D' . $row)->getValue(), + $worksheet->getCell('A' . $row)->getValue(), + trim($worksheet->getCell('B' . $row)->getValue(), '"'), + $worksheet->getCell('D' . $row)->getCalculatedValue(), + trim($worksheet->getCell('C' . $row)->getValue(), '"') + )); +} + +$helper->log('Old method for area conversions, before MS Excel introduced area Units of Measure'); + +$helper->log(sprintf( + '(A%d): Unit of Measure Conversion Formula %s result is %s', + $row, + $worksheet->getCell('H1')->getValue(), + $worksheet->getCell('H1')->getCalculatedValue() +)); diff --git a/samples/Calculations/Engineering/DEC2BIN.php b/samples/Calculations/Engineering/DEC2BIN.php new file mode 100644 index 00000000..2a064c06 --- /dev/null +++ b/samples/Calculations/Engineering/DEC2BIN.php @@ -0,0 +1,47 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [-255], + [-123], + [-15], + [-1], + [5], + [7], + [19], + [51], + [121], + [256], + [511], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=DEC2BIN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Decimal %s is binary %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/DEC2HEX.php b/samples/Calculations/Engineering/DEC2HEX.php new file mode 100644 index 00000000..0a19ae54 --- /dev/null +++ b/samples/Calculations/Engineering/DEC2HEX.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [-255], + [-123], + [-15], + [-1], + [5], + [7], + [19], + [51], + [121], + [256], + [511], + [12345678], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=DEC2HEX(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Decimal %s is hexadecimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/DEC2OCT.php b/samples/Calculations/Engineering/DEC2OCT.php new file mode 100644 index 00000000..fc11a832 --- /dev/null +++ b/samples/Calculations/Engineering/DEC2OCT.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [-255], + [-123], + [-15], + [-1], + [5], + [7], + [19], + [51], + [121], + [256], + [511], + [12345678], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=DEC2OCT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Decimal %s is octal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/DELTA.php b/samples/Calculations/Engineering/DELTA.php new file mode 100644 index 00000000..cd51b161 --- /dev/null +++ b/samples/Calculations/Engineering/DELTA.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [4, 5], + [3, 3], + [0.5, 0], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=DELTA(A' . $row . ',B' . $row . ')'); +} + +$comparison = [ + 0 => 'The values are not equal', + 1 => 'The values are equal', +]; + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Compare values %d and %d - Result is %d - %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + $comparison[$worksheet->getCell('C' . $row)->getCalculatedValue()] + )); +} diff --git a/samples/Calculations/Engineering/ERF.php b/samples/Calculations/Engineering/ERF.php new file mode 100644 index 00000000..e6505888 --- /dev/null +++ b/samples/Calculations/Engineering/ERF.php @@ -0,0 +1,67 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData1 = [ + [0.745], + [1], + [1.5], + [-2], +]; + +$testData2 = [ + [0, 1.5], + [1, 2], + [-2, 1], +]; +$testDataCount1 = count($testData1); +$testDataCount2 = count($testData2); +$testData2StartRow = $testDataCount1 + 1; + +$worksheet->fromArray($testData1, null, 'A1', true); +$worksheet->fromArray($testData2, null, "A{$testData2StartRow}", true); + +for ($row = 1; $row <= $testDataCount1; ++$row) { + $worksheet->setCellValue('C' . $row, '=ERF(A' . $row . ')'); +} + +for ($row = $testDataCount1 + 1; $row <= $testDataCount2 + $testDataCount1; ++$row) { + $worksheet->setCellValue('C' . $row, '=ERF(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +$helper->log('ERF() With a single argument'); +for ($row = 1; $row <= $testDataCount1; ++$row) { + $helper->log(sprintf( + '(C%d): %s The error function integrated between 0 and %f is %f', + $row, + $worksheet->getCell('C' . $row)->getValue(), + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} + +$helper->log('ERF() With two arguments'); +for ($row = $testDataCount1 + 1; $row <= $testDataCount2 + $testDataCount1; ++$row) { + $helper->log(sprintf( + '(C%d): %s The error function integrated between %f and %f is %f', + $row, + $worksheet->getCell('C' . $row)->getValue(), + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/ERFC.php b/samples/Calculations/Engineering/ERFC.php new file mode 100644 index 00000000..5e7bcc6d --- /dev/null +++ b/samples/Calculations/Engineering/ERFC.php @@ -0,0 +1,41 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [0], + [0.5], + [1], + [-1], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=ERFC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): %s The complementary error function integrated by %f and infinity is %f', + $row, + $worksheet->getCell('C' . $row)->getValue(), + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/GESTEP.php b/samples/Calculations/Engineering/GESTEP.php new file mode 100644 index 00000000..73f0a31c --- /dev/null +++ b/samples/Calculations/Engineering/GESTEP.php @@ -0,0 +1,53 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [5, 4], + [5, 5], + [4, 5], + [-4, -5], + [-5, -4], + [1], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=GESTEP(A' . $row . ',B' . $row . ')'); +} + +$comparison = [ + 0 => 'Value %d is less than step %d', + 1 => 'Value %d is greater than or equal to step %d', +]; + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): Compare value %d and step %d - Result is %d - %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + sprintf( + $comparison[$worksheet->getCell('C' . $row)->getCalculatedValue()], + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + ) + )); +} diff --git a/samples/Calculations/Engineering/HEX2BIN.php b/samples/Calculations/Engineering/HEX2BIN.php new file mode 100644 index 00000000..2ad08925 --- /dev/null +++ b/samples/Calculations/Engineering/HEX2BIN.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [3], + [8], + [42], + [99], + ['A2'], + ['F0'], + ['100'], + ['128'], + ['1AB'], + ['1FF'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=HEX2BIN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Hexadecimal %s is binary %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/HEX2DEC.php b/samples/Calculations/Engineering/HEX2DEC.php new file mode 100644 index 00000000..745d4110 --- /dev/null +++ b/samples/Calculations/Engineering/HEX2DEC.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['08'], + ['42'], + ['A2'], + ['400'], + ['1000'], + ['1234'], + ['ABCD'], + ['C3B0'], + ['FFFFFFFFF'], + ['FFFFFFFFFF'], + ['FFFFFFF800'], + ['FEDCBA9876'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=HEX2DEC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Hexadecimal %s is decimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/HEX2OCT.php b/samples/Calculations/Engineering/HEX2OCT.php new file mode 100644 index 00000000..3608c1bb --- /dev/null +++ b/samples/Calculations/Engineering/HEX2OCT.php @@ -0,0 +1,46 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['08'], + ['42'], + ['A2'], + ['400'], + ['100'], + ['1234'], + ['ABCD'], + ['C3B0'], + ['FFFFFFFFFF'], + ['FFFFFFF800'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=HEX2OCT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Hexadecimal %s is octal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMABS.php b/samples/Calculations/Engineering/IMABS.php new file mode 100644 index 00000000..9c6b843c --- /dev/null +++ b/samples/Calculations/Engineering/IMABS.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMABS(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The absolute value of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMAGINARY.php b/samples/Calculations/Engineering/IMAGINARY.php new file mode 100644 index 00000000..99138938 --- /dev/null +++ b/samples/Calculations/Engineering/IMAGINARY.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMAGINARY(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The imaginary component of %s is %f', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMARGUMENT.php b/samples/Calculations/Engineering/IMARGUMENT.php new file mode 100644 index 00000000..e559e951 --- /dev/null +++ b/samples/Calculations/Engineering/IMARGUMENT.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMARGUMENT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Theta Argument of %s is %f radians', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCONJUGATE.php b/samples/Calculations/Engineering/IMCONJUGATE.php new file mode 100644 index 00000000..3b4429ed --- /dev/null +++ b/samples/Calculations/Engineering/IMCONJUGATE.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCONJUGATE(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Conjugate of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCOS.php b/samples/Calculations/Engineering/IMCOS.php new file mode 100644 index 00000000..5b8f81ea --- /dev/null +++ b/samples/Calculations/Engineering/IMCOS.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCOS(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Cosine of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCOSH.php b/samples/Calculations/Engineering/IMCOSH.php new file mode 100644 index 00000000..9a393766 --- /dev/null +++ b/samples/Calculations/Engineering/IMCOSH.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCOSH(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Hyperbolic Cosine of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCOT.php b/samples/Calculations/Engineering/IMCOT.php new file mode 100644 index 00000000..e3d980cd --- /dev/null +++ b/samples/Calculations/Engineering/IMCOT.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCOT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Cotangent of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCSC.php b/samples/Calculations/Engineering/IMCSC.php new file mode 100644 index 00000000..ab6695d0 --- /dev/null +++ b/samples/Calculations/Engineering/IMCSC.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCSC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Cosecant of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMCSCH.php b/samples/Calculations/Engineering/IMCSCH.php new file mode 100644 index 00000000..4513d9e9 --- /dev/null +++ b/samples/Calculations/Engineering/IMCSCH.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMCSCH(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Hyperbolic Cosecant of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMDIV.php b/samples/Calculations/Engineering/IMDIV.php new file mode 100644 index 00000000..9512be57 --- /dev/null +++ b/samples/Calculations/Engineering/IMDIV.php @@ -0,0 +1,42 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i', '5-3i'], + ['3+4i', '5+3i'], + ['-238+240i', '10+24i'], + ['1+2i', 30], + ['1+2i', '2i'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=IMDIV(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Quotient of %s and %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMEXP.php b/samples/Calculations/Engineering/IMEXP.php new file mode 100644 index 00000000..7f5837b2 --- /dev/null +++ b/samples/Calculations/Engineering/IMEXP.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMEXP(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Exponential of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMLN.php b/samples/Calculations/Engineering/IMLN.php new file mode 100644 index 00000000..95618257 --- /dev/null +++ b/samples/Calculations/Engineering/IMLN.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMLN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Natural Logarithm of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMLOG10.php b/samples/Calculations/Engineering/IMLOG10.php new file mode 100644 index 00000000..d501c3de --- /dev/null +++ b/samples/Calculations/Engineering/IMLOG10.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMLOG10(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Base-10 Logarithm of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMLOG2.php b/samples/Calculations/Engineering/IMLOG2.php new file mode 100644 index 00000000..25986b39 --- /dev/null +++ b/samples/Calculations/Engineering/IMLOG2.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMLOG2(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Base-2 Logarithm of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMPOWER.php b/samples/Calculations/Engineering/IMPOWER.php new file mode 100644 index 00000000..c6674fbe --- /dev/null +++ b/samples/Calculations/Engineering/IMPOWER.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i', 2], + ['5-12i', 2], + ['3.25+7.5i', 3], + ['3.25-12.5i', 2], + ['-3.25+7.5i', 3], + ['-3.25-7.5i', 4], + ['0-j', 5], + ['0-2.5j', 3], + ['0+j', 2.5], + ['0+1.25j', 2], + [4, 3], + [-2.5, 2], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=IMPOWER(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): %s raised to the power of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMPRODUCT.php b/samples/Calculations/Engineering/IMPRODUCT.php new file mode 100644 index 00000000..f81bc666 --- /dev/null +++ b/samples/Calculations/Engineering/IMPRODUCT.php @@ -0,0 +1,42 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i', '5-3i'], + ['3+4i', '5+3i'], + ['-238+240i', '10+24i'], + ['1+2i', 30], + ['1+2i', '2i'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=IMPRODUCT(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Product of %s and %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMREAL.php b/samples/Calculations/Engineering/IMREAL.php new file mode 100644 index 00000000..4e537c0f --- /dev/null +++ b/samples/Calculations/Engineering/IMREAL.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMREAL(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The real component of %s is %f radians', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSEC.php b/samples/Calculations/Engineering/IMSEC.php new file mode 100644 index 00000000..e6c524b3 --- /dev/null +++ b/samples/Calculations/Engineering/IMSEC.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMSEC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Secant of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSECH.php b/samples/Calculations/Engineering/IMSECH.php new file mode 100644 index 00000000..e07b6e08 --- /dev/null +++ b/samples/Calculations/Engineering/IMSECH.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMSECH(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Hyperbolic Secant of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSIN.php b/samples/Calculations/Engineering/IMSIN.php new file mode 100644 index 00000000..d3b8c281 --- /dev/null +++ b/samples/Calculations/Engineering/IMSIN.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMSIN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Sine of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSINH.php b/samples/Calculations/Engineering/IMSINH.php new file mode 100644 index 00000000..ac0a9039 --- /dev/null +++ b/samples/Calculations/Engineering/IMSINH.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMSINH(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Hyperbolic Sine of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSQRT.php b/samples/Calculations/Engineering/IMSQRT.php new file mode 100644 index 00000000..c2573c91 --- /dev/null +++ b/samples/Calculations/Engineering/IMSQRT.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMSQRT(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Square Root of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSUB.php b/samples/Calculations/Engineering/IMSUB.php new file mode 100644 index 00000000..90bd27a4 --- /dev/null +++ b/samples/Calculations/Engineering/IMSUB.php @@ -0,0 +1,42 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i', '5-3i'], + ['3+4i', '5+3i'], + ['-238+240i', '10+24i'], + ['1+2i', 30], + ['1+2i', '2i'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=IMSUB(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Difference between %s and %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMSUM.php b/samples/Calculations/Engineering/IMSUM.php new file mode 100644 index 00000000..2a8be320 --- /dev/null +++ b/samples/Calculations/Engineering/IMSUM.php @@ -0,0 +1,42 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i', '5-3i'], + ['3+4i', '5+3i'], + ['-238+240i', '10+24i'], + ['1+2i', 30], + ['1+2i', '2i'], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('C' . $row, '=IMSUM(A' . $row . ', B' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Sum of %s and %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getValue(), + $worksheet->getCell('C' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/IMTAN.php b/samples/Calculations/Engineering/IMTAN.php new file mode 100644 index 00000000..ffaa53b2 --- /dev/null +++ b/samples/Calculations/Engineering/IMTAN.php @@ -0,0 +1,48 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + ['3+4i'], + ['5-12i'], + ['3.25+7.5i'], + ['3.25-12.5i'], + ['-3.25+7.5i'], + ['-3.25-7.5i'], + ['0-j'], + ['0-2.5j'], + ['0+j'], + ['0+1.25j'], + [4], + [-2.5], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=IMTAN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(E%d): The Tangent of %s is %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/OCT2BIN.php b/samples/Calculations/Engineering/OCT2BIN.php new file mode 100644 index 00000000..9c4bbf86 --- /dev/null +++ b/samples/Calculations/Engineering/OCT2BIN.php @@ -0,0 +1,47 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [3], + [7], + [42], + [70], + [72], + [77], + [100], + [127], + [177], + [456], + [567], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=OCT2BIN(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Octal %s is binary %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/OCT2DEC.php b/samples/Calculations/Engineering/OCT2DEC.php new file mode 100644 index 00000000..ea6afb2f --- /dev/null +++ b/samples/Calculations/Engineering/OCT2DEC.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [3], + [7], + [42], + [70], + [72], + [77], + [100], + [127], + [177], + [456], + [4567], + [7777700001], + [7777776543], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=OCT2DEC(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Octal %s is decimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/samples/Calculations/Engineering/OCT2HEX.php b/samples/Calculations/Engineering/OCT2HEX.php new file mode 100644 index 00000000..47e9b6e1 --- /dev/null +++ b/samples/Calculations/Engineering/OCT2HEX.php @@ -0,0 +1,49 @@ +titles($category, $functionName, $description); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testData = [ + [3], + [12], + [42], + [70], + [72], + [77], + [100], + [127], + [177], + [456], + [4567], + [7777700001], + [7777776543], +]; +$testDataCount = count($testData); + +$worksheet->fromArray($testData, null, 'A1', true); + +for ($row = 1; $row <= $testDataCount; ++$row) { + $worksheet->setCellValue('B' . $row, '=OCT2HEX(A' . $row . ')'); +} + +// Test the formulae +for ($row = 1; $row <= $testDataCount; ++$row) { + $helper->log(sprintf( + '(B%d): Octal %s is hexadecimal %s', + $row, + $worksheet->getCell('A' . $row)->getValue(), + $worksheet->getCell('B' . $row)->getCalculatedValue(), + )); +} diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php index 4d4bc07e..6aaf1faa 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php @@ -57,7 +57,7 @@ class Compare * * @param array|float $number the value to test against step * Or can be an array of values - * @param array|float $step The threshold value. If you omit a value for step, GESTEP uses zero. + * @param null|array|float $step The threshold value. If you omit a value for step, GESTEP uses zero. * Or can be an array of values * * @return array|int|string (string in the event of an error) @@ -72,7 +72,7 @@ class Compare try { $number = EngineeringValidations::validateFloat($number); - $step = EngineeringValidations::validateFloat($step); + $step = EngineeringValidations::validateFloat($step ?? 0.0); } catch (Exception $e) { return $e->getMessage(); } diff --git a/tests/data/Calculation/DateTime/DATE.php b/tests/data/Calculation/DateTime/DATE.php index 72816b76..d8b4303a 100644 --- a/tests/data/Calculation/DateTime/DATE.php +++ b/tests/data/Calculation/DateTime/DATE.php @@ -1,7 +1,9 @@