|
Boost Users : |
Subject: Re: [Boost-users] [accumulators] Is there a reset function yet?
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-05-21 15:23:38
> > By the way, does the accumulator do something to prevent an overflow
> when I
> > add up everything into one variable?
>
> No. It uses native intrinsics for raw performance. If you want anything
> fancy, you can use your own UDT for samples that check for overflow.
> Some construction required. :-( If you do build such a thing, I would
> consider making it an official part of Accumulators.
> Eric Niebler
> BoostPro Computing
Hey Eric, I wonder, did we cross paths back in the day, on Compuserve like DDJFORUM or CLMFORUM? Your name is familiar.
I faced a similar overflow problem for general work. I'm worried about adding signed and unsigned types, as well as different sizes of ints. I made an overflow_add and overflow_subtract template that just does the work in a larger type if one is available, and does necessary checking for the largest type. Rather than declare variables of some "checked" wrapper with its own overloaded operators, I just use overflow_add occasionally where needed.
It really bugs me that I could not draw upon the CPU's native checking. It knows! So why do I have to go out of my way to figure it out based on primitive principles?
I haven't done much writing lately, but I could share this with someone who wants to discuss it. It would need a little work to make it more portable: I know what the largest type is. Boost has a module that does fancy casting between integral types that is rather configurable; I know that an error is an overflow exception. Undoubtedly the "policy" can be separated out from the tricky part of actually doing the detection for every possible case, making that reusable in a larger sense.
--John
John M. Dlugosz
TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net