Philluminati schrieb:
> I am writing a poker game which needs to work with cash. I am aware
> that there are problems with floats that make them unsuitable for
> storing money values.
The problem is not on "storing money values". It is that float doesn't
give you much guarantees how and when rounding happens.
> On top of this I may be expected to do
> operations such as £10.52 / 3. Which data type should I use instead?
> Is there an Industry standard one?
BCD probably? You then need to implement it yourself, though.
(Might be more elegant to do this in C++, then, though).
> Further to this, is anyone away of legally what the obligations would
> be when the outcome is 3.566666667? does the customer get 56 or 57p?
> Do I need to track the remaining .003333 and use it in other
> operations?
I have no idea.
> And finally, why do I see people typedef values in C and, for example,
> use size_t rather than an int? Why is the type hidden like this?
There is no type hidden anywhere. size_t *is* a type. And it's likely
not equivalent to int since size_t is unsigned.
> Surely it can lead to bugs and changing a data type later in
> development can allow bitwise and maths operations to become un-
> trustable?
You do not change the type. Rather, the type depends on the architecture
you develop on. The idea is that the same program works the same way
regardless where you compile it. For example, size_t might be 32 bit
wide on a 32 bit machine, but 64 bit wide on a 64 bit machine. size_t is
large enough to hold the size of any type (that's how it is defined).
"int" has an implementation defined size that might be 32 or 64 bit (on
my compiler, it is 32 bit on both the 32 and the 64 bit architecture,
unlike size_t)
> In my own applications I have been typdef'ing structures
> merely to remove the requirement to write "struct" everywhere and I
> see how shortening the name of unsigned long to ulng would be useful
> but I don't see it's benefit in some cases. So why do people use it?
To make the code ****table. The code I have here compiles on Linux,
Windows, AIX, Solaris and probably a couple of other platforms. The
types I use are defined such that operations generate identical output
regardless of the platform; this does not hold for "int" for example.
So long,
Thomas
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|