Click to See Complete Forum and Search --> : Does cents*cents make any sense? (no pun intended)


Paladaxar
February 18th, 2008, 11:02 PM
WARNING: Theoretical question ahead...and may not be worth your time.

My friends and I are arguing right now about sub ranges. If we were to make a type "cents" that consists of the integers from 0-99, should we be able to multiply this type with itself or not?

I agree that 4*5 cents = 20 cents. Thats fine.

But 4 cents * 5 cents = 20 cents^2. Cents^2 is a meaningless unit.

So, I think that int*cent should be allowed, but cent*cent should not be allowed and should throw an error...because it makes no sense.

They are saying that any sub range needs to support all of the operations that its parent allows.

Any thoughts that might help us clear this up? I did a quick google search to see if i could come up with a professional opinion (a book or something) but didnt find anything.

Ejaz
February 18th, 2008, 11:31 PM
[ Moved Thread ]

pm_kirkham
February 19th, 2008, 05:25 AM
The 'cents' type isn't a subset of the 'integer' type - it's a measured value, not a pure number.

In effect a measured value consists of a tuple of <value, measure> such that addition/subtraction are only defined on equivalent measures and multiplication/division are applied to both value and measure. Pure numbers are dimensionless so take a unit measure, so the type of <integer, unit> * <integer, cent> will be <integer, unit*cent = cent>. Such systems don't usually care whether or not combinations of measures are meaningful - say you wanted to do statistical analysis of your cash flow, then you'd end up with intermediate values in cents^^2. Usually dimensional equivalence is used, but that isn't entirely typesafe - for example torque and work have the same dimensions (Nm in SI) but aren't physically equivalent.

Since a measured value is a disjoint type to a pure number, rules about sub-ranges supporting all operations of a parent don't apply, even if they did otherwise (they don't usually when considering mathematical operations as a sub-set of a group isn't necessarily a group).

(some writers use 'quantity' rather than 'measured value')