$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] [boostcon][proto] Suggestion for LIAW session: fixed-point numbers
From: Ravi (lists_ravi_at_[hidden])
Date: 2011-03-13 17:24:34
Hi,
Are there any proto-based ideas for the library-in-a-week sessions? If not,
would building a fixed-point data type be of interest? The domain is narrow
enough that something useful can be accomplished in 4 sessions, but of large
enough scope to present opportunities for exploring proto in depth. A fairly
simple design follows representing a number:
fixed_number<int width,
int ulp, // 2^{ulp} is the smallest increment possible
bool signed,
template assigner<first, last, signed> >
'assigner' handles rounding/truncation/wrapping/etc when assigning another
number (floating-point or fixed-point) to the current one. Internally, each
fixed-point number would be represented by a boost::uint64_t or a
boost::int64_t (limiting the maximum precision allowed). As an example,
fixed_number<5, -3, false>
would represent a data type that would go from 0 to 3.875 in steps of 0.125.
Proto would be used for creating all arithmetic operations since the return
type of a+b could be different from the type of either a or b. A bonus would
involve getting the fixed-point data type to play well with std::complex (and,
yes, I am aware that std::complex is not designed to work with anything other
than double and float, and will require specialization in the std namespace).
If there is sufficient interest, I could even provide a starting point with
+,-,* implemented; / would take more time. The design above is intended as a
starting point for discussion and I am most definitely not wedded to it. I am
a tyro when it comes to proto, and hence would need someone with more proto
expertise to guide the discussion.
Regards,
Ravi