Neil Heller wrote in a message to All:
NH> Given the following:
NH> string foo = "12345678";
NH> Is there a built-in or easily obtainable function for
NH> converting foo to a "BCD type" (if there is such)? Would
NH> such a conversion automatically "fold" foo so that the
NH> result would only require 4 bytes instead of the minimum
NH> (9?) otherwise required?
I think the overhead involved in maintaining folded values does not outweight
the troubles, especially when floating values are involved (like $15.6). In
cases where a very large number of small values is used it might be
worthwile, but I suppose you'd better use integers in that case as they will
certainly be faster and smaller.
NH> Just thinking about it some more, it seems that a BCD class
NH> would be in order. How could I go about investigating the
NH> existance of same?
AFAIK, A number of compilers have a BCD class (Borland, IBM). I'd start
searching the internet for an implementation if I need one and my compiler
hasn't one. The CUG (C Users Group) might be another source to check. Finally
SNIPPETS might have an implementation.
NH> Would anyone care to speculate on the comparitive
NH> difficulties of doing this in C as opposed to C++?
In C you would need a different syntax to use the BCDs. In C++ you can make
your class 'part of the language' by implementing the correct functions.
The actual algorithms however would be the same in both languages. You can
build a C++ class from a C library implementing the necessary operations if
you want (This makes it probably more maintainable if the code is used in C
and in C++ projects, but it might introduce some overhead in the C++
sion).
mvg/wr
--- timEd/2 1.01.g3+
---------------
* Origin: LightHouse BBS ==> I am a H.U.G.O. Member ! (2:285/324.3)
|