From 82022a10410672916ef7b135c1c68a57a486c159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Sat, 21 Aug 2021 19:58:53 +0100 Subject: [PATCH] Fixes #10 --- changelog.md | 4 ++++ hotxlfp/formulas/mathtrig.py | 9 ++++++--- setup.py | 4 ++-- tests/test_mathtrig.py | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 72a9f76..99c0f82 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # hotxlfp changelog +## 0.0.15 + +* Fixed bugs in FLOOR function. + ## 0.0.14 * Fixed using a parser within a parser. diff --git a/hotxlfp/formulas/mathtrig.py b/hotxlfp/formulas/mathtrig.py index 9bd90e0..96458ab 100644 --- a/hotxlfp/formulas/mathtrig.py +++ b/hotxlfp/formulas/mathtrig.py @@ -272,11 +272,14 @@ def FLOOR(number, significance=1): if number > 0 and not significance > 0: return error.NUM - significance = abs(significance) + abs_significance = abs(significance) if number >= 0: - return math.floor(number / significance) * significance + return math.floor(number / abs_significance) * abs_significance else: - return -1 * math.floor(abs(number) / significance) * significance + func = math.floor + if significance > 0: + func = math.ceil + return -1 * func(abs(number) / abs_significance) * abs_significance @dispatcher.register_for('POWER') diff --git a/setup.py b/setup.py index 071e12a..b0868cc 100644 --- a/setup.py +++ b/setup.py @@ -4,14 +4,14 @@ setup( name='hotxlfp', - version='0.0.14', + version='0.0.15', packages=['hotxlfp', 'hotxlfp._compat', 'hotxlfp._compat.py3', 'hotxlfp.helper', 'hotxlfp.formulas', 'hotxlfp.grammarparser'], license='MIT', test_suite='tests', author='Leonel Câmara', author_email='leonelcamara@gmail.com', url='https://github.com/aidhound/hotxlfp', - download_url='https://github.com/aidhound/hotxlfp/archive/0.0.13.tar.gz', + download_url='https://github.com/aidhound/hotxlfp/archive/0.0.15.tar.gz', keywords=['excel', 'formula', 'parser'], install_requires=['ply', 'python-dateutil'], long_description='\n'.join(l for l in open('README.md', encoding="utf-8").readlines() if not l.startswith('[!')), diff --git a/tests/test_mathtrig.py b/tests/test_mathtrig.py index 8405c0e..d2b6c7a 100644 --- a/tests/test_mathtrig.py +++ b/tests/test_mathtrig.py @@ -290,6 +290,13 @@ def test_floor(self): ret = p.parse('FLOOR(0.234,0.01)') self.assertEqual(ret['result'], 0.23) self.assertEqual(ret['error'], None) + ret = p.parse('FLOOR(-5.6; 1)') + self.assertEqual(ret['result'], -6) + self.assertEqual(ret['error'], None) + ret = p.parse('FLOOR(-5.6; -1)') + self.assertEqual(ret['result'], -5) + self.assertEqual(ret['error'], None) + def test_quotient(self): p = Parser(debug=True)