Funny issue with casting double to ulong

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 4 06:29:53 PDT 2017


On Tuesday, 4 July 2017 at 12:32:26 UTC, Patrick Schluter wrote:
> In times of lore, BCD floats were very common. The Sharp Pocket 
> Computer used a BCD float format and writing machine code on 
> them confronts one with the format. The TI-99/4A home computer 
> also used a BCD float format in its Basic interpreter. It had 
> the same properties as the float format of the TI calculators, 
> I.e. 10 visible significant digits (+ 3 hidden digits) and 
> exponents going from -99 to +99.

If you look at the instruction set for 6502 (and probably similar 
4-8bit CPU's) they literally don't deal with anything other than 
8bit add/subtraction & other basic binary operators. Without 
multiplication or division all of that has to be simulated in 
software. And only needing 10 instructions to do just about 
everything, well...

BCD of course has a big advantage built-in: Because it's all 
base10, converting BCD to a string and printing it is very fast 
(as well as precise). And with 1 byte reserved for exponent, 
raising/lowering the level is also very very easy and goes a very 
large range.

There's also a series of algorithms for calculating some of the 
more complex functions using small tables or an iteration of 
shift & add which is implemented on calculators allowing a 
simpler (and reduced) instruction set or fewer transistors to 
make calculators work (CORDIC). It's actually pretty fascinating 
to read about.

BCD could still be an option though... I could probably write 
one; Although with doubles avaliable, you probably don't need it.


More information about the Digitalmars-d-learn mailing list