Rounding problem with stock split factor

Mark Thomas marks.subs at gmail.com
Tue Jan 1 08:56:47 GMT 2019


Hi,

I have a stock that has had a 6:1 share consolidation, so would reduce the
quantity down to one for every 6 currently held.

I tried entering this as a "Split Shares" activity with a factor of 0.16667
but this causes a divide by zero floating point exception,  see below for
the backtrace.  Its the same in 5.0.1 and 5.0.2.

The critical point is that the stock is defined with  a 1/1 fraction (ie:
whole stocks) and that this causes the split factor in the activity to be
rounded down to zero.

This rounding  is also an issue with normal splits of whole stocks, for
example a 3:2 split entered as factor 1.5 as per the manual is rounded up
to 2.

The problem code appears to be in in
kmymoney/dialogs/investtransactioneditor.cpp where
InvestTransactionEditor::createTransaction() calls:

s0.setShares(MyMoneyMoney(s0.shares().convertDenominator(securityFraction,
roundingMethod)));

with securityFraction is 1 but the value in s0 is the factor, not the total
quantity of shares, and needs to keep the precision it was entered with.

I think the rounding should be done later on the new balance of shares
after the split factor is applied and not on the factor itself.

It does look like an issue to me but this is the first time I've delved
into the code.

Thanks,
-Mark




          if (t->transaction().isStockSplit()) {
            balance /= split.shares();                          <<<
split.shares() is 0

#0  0x00007fffeb24e55a in __gmp_exception () at
/usr/lib/x86_64-linux-gnu/libgmp.so.10
...
#3  0x00007ffff4b90448 in AlkValue::operator/=(AlkValue const&) () at
/usr/lib/x86_64-linux-gnu/libalkimia5.so.7
#4  0x00005555556a4da0 in KGlobalLedgerViewPrivate::loadView()
(this=0x555555d50ce0) at
kmymoney-5.0.2/kmymoney/views/kgloballedgerview_p.h:793
#5  0x00005555556924b8 in KGlobalLedgerView::refresh()
(this=0x5555561db540) at
kmymoney-5.0.2/kmymoney/views/kgloballedgerview.cpp:152
#6  0x000055555569781f in
KGlobalLedgerView::slotLeaveEditMode(KMyMoneyRegister::SelectedTransactions
const&) (this=0x5555561db540, list=...) at
kmymoney-5.0.2/kmymoney/views/kgloballedgerview.cpp:963
#7  0x00005555556b3bef in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>,
QtPrivate::List<KMyMoneyRegister::SelectedTransactions const&>, void, void
(KGlobalLedgerView::*)(KMyMoneyRegister::SelectedTransactions
const&)>::call(void
(KGlobalLedgerView::*)(KMyMoneyRegister::SelectedTransactions const&),
KGlobalLedgerView*, void**) (f=
    (void (KGlobalLedgerView::*)(KGlobalLedgerView * const, const
KMyMoneyRegister::SelectedTransactions &)) 0x555555697566
<KGlobalLedgerView::slotLeaveEditMode(KMyMoneyRegister::SelectedTransactions
const&)>, o=0x5555561db540, arg=0x7fffffffd0b0)
    at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:136
#8  0x00005555556b31c8 in QtPrivate::FunctionPointer<void
(KGlobalLedgerView::*)(KMyMoneyRegister::SelectedTransactions
const&)>::call<QtPrivate::List<KMyMoneyRegister::SelectedTransactions
const&>, void>(void
(KGlobalLedgerView::*)(KMyMoneyRegister::SelectedTransactions const&),
KGlobalLedgerView*, void**) (f=
    (void (KGlobalLedgerView::*)(KGlobalLedgerView * const, const
KMyMoneyRegister::SelectedTransactions &)) 0x555555697566
<KGlobalLedgerView::slotLeaveEditMode(KMyMoneyRegister::SelectedTransactions
const&)>, o=0x5555561db540, arg=0x7fffffffd0b0)
    at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:169
#9  0x00005555556b1cac in QtPrivate::QSlotObject<void
(KGlobalLedgerView::*)(KMyMoneyRegister::SelectedTransactions const&),
QtPrivate::List<KMyMoneyRegister::SelectedTransactions const&>,
void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*)
(which=1, this_=0x555556b71be0, r=0x5555561db540, a=0x7fffffffd0b0,
ret=0x0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject_impl.h:120
#10 0x00007ffff11096cf in QMetaObject::activate(QObject*, int, int, void**)
() at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#11 0x000055555582c2ac in
TransactionEditor::finishEdit(KMyMoneyRegister::SelectedTransactions
const&) (this=0x5555574ce6d0, _t1=...) at
kmymoney-5.0.2/debug/kmymoney/dialogs/dialogs_autogen/EWIEGA46WW/moc_transactioneditor.cpp:338
#12 0x000055555581b707 in TransactionEditor::~TransactionEditor()
(this=0x5555574ce6d0, __in_chrg=<optimised out>) at
kmymoney-5.0.2/kmymoney/dialogs/transactioneditor.cpp:129
#13 0x000055555582e690 in
InvestTransactionEditor::~InvestTransactionEditor() (this=0x5555574ce6d0,
__in_chrg=<optimised out>) at
kmymoney-5.0.2/kmymoney/dialogs/investtransactioneditor.cpp:317
#14 0x000055555582e6ac in
InvestTransactionEditor::~InvestTransactionEditor() (this=0x5555574ce6d0,
__in_chrg=<optimised out>) at
kmymoney-5.0.2/kmymoney/dialogs/investtransactioneditor.cpp:319
#15 0x00005555556aa0e7 in
KGlobalLedgerViewPrivate::deleteTransactionEditor() (this=0x555555d50ce0)
at kmymoney-5.0.2/kmymoney/views/kgloballedgerview_p.h:1234
#16 0x000055555569b1fd in KGlobalLedgerView::slotEnterTransaction()
(this=0x5555561db540) at
kmymoney-5.0.2/kmymoney/views/kgloballedgerview.cpp:1551
#17 0x00005555556b3b39 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>,
QtPrivate::List<>, void, void (KGlobalLedgerView::*)()>::call(void
(KGlobalLedgerView::*)(), KGlobalLedgerView*, void**) (f=(void
(KGlobalLedgerView::*)(KGlobalLedgerView * const)) 0x55555569af98
<KGlobalLedgerView::slotEnterTransaction()>, o=0x5555561db540,
arg=0x7fffffffd420) at
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:136
#18 0x00005555556b3183 in QtPrivate::FunctionPointer<void
(KGlobalLedgerView::*)()>::call<QtPrivate::List<>, void>(void
(KGlobalLedgerView::*)(), KGlobalLedgerView*, void**) (f=(void
(KGlobalLedgerView::*)(KGlobalLedgerView * const)) 0x55555569af98
<KGlobalLedgerView::slotEnterTransaction()>, o=0x5555561db540,
arg=0x7fffffffd420) at
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:169
#19 0x00005555556b1bc8 in QtPrivate::QSlotObject<void
(KGlobalLedgerView::*)(), QtPrivate::List<>, void>::impl(int,
QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1,
this_=0x5555561dc980, r=0x5555561db540, a=0x7fffffffd420, ret=0x0)
    at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject_impl.h:120
#20 0x00007ffff11096cf in QMetaObject::activate(QObject*, int, int, void**)
() at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#21 0x00007ffff3086122 in QAction::triggered(bool) () at
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007ffff308880c in QAction::activate(QAction::ActionEvent) () at
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#23 0x0000555555660a8d in QAction::trigger() (this=0x555555df8e10) at
/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qaction.h:184
#24 0x000055555566a868 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>,
QtPrivate::List<>, void, void (QAction::*)()>::call(void (QAction::*)(),
QAction*, void**) (f=(void (QAction::*)(QAction * const)) 0x555555660a70
<QAction::trigger()>, o=0x555555df8e10, arg=0x7fffffffd660) at
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:136
#25 0x000055555566a11d in QtPrivate::FunctionPointer<void
(QAction::*)()>::call<QtPrivate::List<>, void>(void (QAction::*)(),
QAction*, void**) (f=(void (QAction::*)(QAction * const)) 0x555555660a70
<QAction::trigger()>, o=0x555555df8e10, arg=0x7fffffffd660)
    at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:169
#26 0x00005555556694ee in QtPrivate::QSlotObject<void (QAction::*)(),
QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*,
void**, bool*) (which=1, this_=0x555557f268c0, r=0x555555df8e10,
a=0x7fffffffd660, ret=0x0)
    at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject_impl.h:120
#27 0x00007ffff11096cf in QMetaObject::activate(QObject*, int, int, void**)
() at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#28 0x000055555582c669 in TransactionEditor::returnPressed(int)
(this=0x5555574ce6d0, _t1=100) at
kmymoney-5.0.2/debug/kmymoney/dialogs/dialogs_autogen/EWIEGA46WW/moc_transactioneditor.cpp:400
#29 0x000055555582ba3a in TransactionEditor::qt_static_metacall(QObject*,
QMetaObject::Call, int, void**) (_o=0x5555574ce6d0,
_c=QMetaObject::InvokeMetaMethod, _id=11, _a=0x555556b750d0)
    at
kmymoney-5.0.2/debug/kmymoney/dialogs/dialogs_autogen/EWIEGA46WW/moc_transactioneditor.cpp:192
#30 0x00007ffff110a122 in QObject::event(QEvent*) () at
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#31 0x00007ffff308c82c in QApplicationPrivate::notify_helper(QObject*,
QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#32 0x00007ffff30940f4 in QApplication::notify(QObject*, QEvent*) () at
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#33 0x00007ffff10da9a8 in QCoreApplication::notifyInternal2(QObject*,
QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#34 0x00007ffff10dd11d in
QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#35 0x00007ffff11342c3 in  () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#36 0x00007fffe6f40387 in g_main_context_dispatch () at
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#37 0x00007fffe6f405c0 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#38 0x00007fffe6f4064c in g_main_context_iteration () at
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#39 0x00007ffff11338ef in
QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
() at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#40 0x00007ffff10d89ea in
QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#41 0x00007ffff10e1a84 in QCoreApplication::exec() () at
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#42 0x00005555555f3017 in runKMyMoney(QApplication&,
std::unique_ptr<QSplashScreen, std::default_delete<QSplashScreen> >, QUrl
const&, bool) (a=..., splash=std::unique_ptr<QSplashScreen> = {...},
file=..., noFile=false)
    at kmymoney-5.0.2/kmymoney/main.cpp:335
#43 0x00005555555f26f6 in main(int, char**) (argc=2, argv=0x7fffffffdf58)
at kmymoney-5.0.2/kmymoney/main.cpp:243
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20190101/1bf5ea26/attachment-0001.html>


More information about the KMyMoney-devel mailing list