|
Boost Users : |
Subject: Re: [Boost-users] [Accumulators] Questions about the library
From: Matthias Troyer (troyer_at_[hidden])
Date: 2009-08-10 13:20:41
On Jun 25, 2009, at 8:53 AM, dhruva wrote:
>
>> Date: Thu, 25 Jun 2009 03:41:49 -0700 (PDT)
>> From: adish
>> Subject: Re: [Boost-users] [Accumulators] Questions about the library
>> To: boost-users_at_[hidden]
>>
>>>
>>>> ? ?2. If my platform does not support HW floating point ops, and
>>>> all my
>>>> ? ?sample values are, e.g. ints, is there a way to specify that the
>>>> *computation
>>>> ? ?*and *return value itself* (i.e. result_type, e.g. the mean)
>>>> will be done
>>>> ? ?in ints (naturally, at the cost of precision)?
>>>
>>> I have used UDT as I needed some extra information from the
>>> results (as I was
>> working on data from a time series). The reverse, using a POD like
>> int must be
>> possible. Instead of the first argument being float/double, use an
>> int. If that
>> does not work, you can wrap an int in a UDT, implement some of the
>> operators
>> like '=', '<', '/' depending on the accumulator you plan to use (I
>> did that as I
>> needed to send a UDT).
>>
>> Using an int still returns a float -- which is quite sensible.
>
> You might be able to write a custom extractor which can return an
> int. I have not explored it. I always thought the type you give as
> input is the type that gets returned
It does not since the mean of integers is a floating point type. Doing
means as integers will also not make much sense since the mean is
calculated by dividing the sum of values by the number of values, and
the sum will very soon overflow your integer. However, if you are sure
that the sum will never overflow then you can define your own UDT
wrapping an integer and do all the math using that type. I would not
recommend doing this, though.
Matthias
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