[Python-ideas] Python Numbers as Human Concept Decimal System

random832 at fastmail.us random832 at fastmail.us
Sat Mar 8 04:24:04 CET 2014



On Fri, Mar 7, 2014, at 16:24, Andrew Barnert wrote:
> There is no such thing as copying a binary float exactly into a decimal
> float. Decimal float values are not a superset of binary float values; in
> either direction, you have to round. Which is what Python 2.7+ does.

Actually, arbitrary-precision decimal floats are a superset of binary
floats, because 2 is a factor of 10. As the binary floats get smaller
you need more and more digits to represent the decimal though.

>>> decimal.Decimal(1/2**1074)
Decimal('4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625E-324')


More information about the Python-ideas mailing list