Bitcoin Forum
April 26, 2024, 07:12:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Integer or float used in Bitcoin?  (Read 7352 times)
NeoCortX (OP)
Newbie
*
Offline Offline

Activity: 22
Merit: 0



View Profile WWW
December 21, 2012, 02:12:12 AM
 #1

What data type is used in Bitcoin to store the value of a transaction?

I doubt it's double or float due to rounding errors. My guess is that it's integer or long with a system for moving the decimal. Can someone help explain this?

I tried Google, but it said just "I don't know".

Thanks.
1714158752
Hero Member
*
Offline Offline

Posts: 1714158752

View Profile Personal Message (Offline)

Ignore
1714158752
Reply with quote  #2

1714158752
Report to moderator
The grue lurks in the darkest places of the earth. Its favorite diet is adventurers, but its insatiable appetite is tempered by its fear of light. No grue has ever been seen by the light of day, and few have survived its fearsome jaws to tell the tale.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714158752
Hero Member
*
Offline Offline

Posts: 1714158752

View Profile Personal Message (Offline)

Ignore
1714158752
Reply with quote  #2

1714158752
Report to moderator
pc
Sr. Member
****
Offline Offline

Activity: 253
Merit: 250


View Profile
December 21, 2012, 02:25:42 AM
 #2

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.
Stephen Gornick
Legendary
*
Offline Offline

Activity: 2506
Merit: 1010


View Profile
December 21, 2012, 05:56:37 AM
 #3

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.

The Bitcoin.org client will display the number according to the value of the units setting (i.e.,. BTC, mBTC, or uBTC).

For instance;

Here's the raw data for a transaction:
 - http://blockchain.info/rawtx/97990146ef27291626518b39b0217caa38276d5ed16306ef233d90d0c1414924

The inputs are:
 "value":5103074576    <--   51.03074576 BTC
 "value":4882066520    <---  48.82066520 BTC

There is just one output, and the value of it is:
 "value":9985141096    <--   99.85141096 BTC

Unichange.me

            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █


DannyHamilton
Legendary
*
Offline Offline

Activity: 3374
Merit: 4606



View Profile
December 21, 2012, 10:57:07 AM
 #4

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.
Which is why the "Satoshi" is currently the smallest unit of value that can be used in a transaction.

This is also why statements suggesting "infinitely divisible", and "we can just add more decimals" would not be quite as simple to implement as some people believe.  If it becomes necessary to do so, then it is possible, just not as easy to do as it is to say.
TalkingAntColony
Member
**
Offline Offline

Activity: 62
Merit: 10


View Profile
December 21, 2012, 04:48:03 PM
 #5

What would it take to update the protocol to, say, a 128-bit integer?
DannyHamilton
Legendary
*
Offline Offline

Activity: 3374
Merit: 4606



View Profile
December 21, 2012, 05:10:59 PM
 #6

What would it take to update the protocol to, say, a 128-bit integer?
If you are suggesting that as a way to increase the number of decimal places a bitcoin can be split into, then it would take more than increasing the number of bits in the integer, you'd also have to multiply all values in the blockchain by some multiple of 10 to increase the number of digits in the values.  This would be a "hard fork", meaning that anybody who didn't upgrade, would continue to operate on the old system, and anybody who did upgrade would be operating on the new system.  This creates essentially two incompatible cryptocurrencies each calling themselves "bitcoin".
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
December 21, 2012, 05:20:03 PM
 #7

I tried Google, but it said just "I don't know".
no you didn't
https://bitcointalk.org/index.php?topic=13837

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
December 21, 2012, 05:40:51 PM
 #8

This creates essentially two incompatible cryptocurrencies each calling themselves "bitcoin".
Assuming that there is anyone using the old one— the way you'd actually do this change is that you'd write it, validate it, test it.. and then agree that it would become active as of block  now+16 years (or whatever).  Then everyone has 16 years to update, and after than new blocks are interpreted the new way.

This sort of thing could be done for changes which are clearly necessary and uncontroversial— and I'd guess a precision increase would fit that bill if bitcoin ever deflated to the point where it seemed like it would eventually be an issue—, but it's not generally viable otherwise.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3374
Merit: 4606



View Profile
December 21, 2012, 05:56:40 PM
 #9

This creates essentially two incompatible cryptocurrencies each calling themselves "bitcoin".
Assuming that there is anyone using the old one— the way you'd actually do this change is that you'd write it, validate it, test it.. and then agree that it would become active as of block  now+16 years (or whatever).  Then everyone has 16 years to update, and after than new blocks are interpreted the new way.

This sort of thing could be done for changes which are clearly necessary and uncontroversial— and I'd guess a precision increase would fit that bill if bitcoin ever deflated to the point where it seemed like it would eventually be an issue—, but it's not generally viable otherwise.

Agreed.  That would be why I originally stated:

. . . statements suggesting "infinitely divisible", and "we can just add more decimals" would not be quite as simple to implement as some people believe.  If it becomes necessary to do so, then it is possible, just not as easy to do as it is to say.
2_Thumbs_Up
Sr. Member
****
Offline Offline

Activity: 323
Merit: 251


View Profile
December 22, 2012, 09:58:56 AM
 #10

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.
2^64 = 1,8*10^19

Currently, the amount of bitcoins will never exceed 2,1*10^15

Wouldn't it have made more sence to let the supply of bitcoins geometrically approach 2^64? That would have given us a few more decimals without actually incresing the cost for storing or making a transaction. Or am I missing something?
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
December 22, 2012, 01:13:22 PM
 #11

What would it take to update the protocol to, say, a 128-bit integer?
It wouldn't need to be done that way. Not all of the 64 bits are used at the moment, so one of the spare bits could be used to indicate that the value is to be scaled. So technically it's straightforward, but as others have explained it's a "hard fork", so the change would need to be broadly aged well in advance of it's implementation.

The change may never be needed anyway, as some kind of sub-ledger may become popular for handling small payments.

Meh.  The value field is such a small part of the transaction that making it wider is probably cheaper overall than having to put up with the headaches of scaled formats.

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.
2^64 = 1,8*10^19

Currently, the amount of bitcoins will never exceed 2,1*10^15

Wouldn't it have made more sence to let the supply of bitcoins geometrically approach 2^64? That would have given us a few more decimals without actually incresing the cost for storing or making a transaction. Or am I missing something?

Most of the constants in bitcoin are totally arbitrary.  I don't see any reason to believe that 264 base units would be "better" in any meaningful way than ~251, and the extra bits allow for headroom in accounting.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
prezbo
Sr. Member
****
Offline Offline

Activity: 430
Merit: 250


View Profile
December 22, 2012, 03:15:01 PM
 #12

What would it take to update the protocol to, say, a 128-bit integer?
It wouldn't need to be done that way. Not all of the 64 bits are used at the moment, so one of the spare bits could be used to indicate that the value is to be scaled. So technically it's straightforward, but as others have explained it's a "hard fork", so the change would need to be broadly aged well in advance of it's implementation.

The change may never be needed anyway, as some kind of sub-ledger may become popular for handling small payments.

Meh.  The value field is such a small part of the transaction that making it wider is probably cheaper overall than having to put up with the headaches of scaled formats.

Values in bitcoind are 64-bit integers, with a convention that "a bitcoin" means put the decimal point 8 places from the right.
2^64 = 1,8*10^19

Currently, the amount of bitcoins will never exceed 2,1*10^15

Wouldn't it have made more sence to let the supply of bitcoins geometrically approach 2^64? That would have given us a few more decimals without actually incresing the cost for storing or making a transaction. Or am I missing something?

Most of the constants in bitcoin are totally arbitrary.  I don't see any reason to believe that 264 base units would be "better" in any meaningful way than ~251, and the extra bits allow for headroom in accounting.
If I understand correctly, he's trying to say bitcoin has 2.1*10^15 base units and a 64 bit integer can store 1.8*10^19 values, meaning we could have 3 decimal points greater precision using the same data type.
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
December 22, 2012, 04:49:18 PM
 #13

Actually the fact that all bitcoins fit within 2**53 is quite a happy accident. It means that integer-satoshi amounts can be represented exactly by the IEEE decimal64 type, which provides one route towards practically infinite divisibility by using exact arbitrary-precision rational arithmetic and decimal64 for serialization.

Freicoin already implements arbitrary-precision internal arithmetic, and decimal64 support could be added by a new transaction serialization version. As others have mentioned though, there's not really a need until sub-satoshi amounts have any real-world value.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
casascius
Mike Caldwell
VIP
Legendary
*
Offline Offline

Activity: 1386
Merit: 1136


The Casascius 1oz 10BTC Silver Round (w/ Gold B)


View Profile WWW
December 22, 2012, 05:15:06 PM
 #14

Actually the fact that all bitcoins fit within 2**53 is quite a happy accident. It means that integer-satoshi amounts can be represented exactly by the IEEE decimal64 type, which provides one route towards practically infinite divisibility by using exact arbitrary-precision rational arithmetic and decimal64 for serialization.

Freicoin already implements arbitrary-precision internal arithmetic, and decimal64 support could be added by a new transaction serialization version. As others have mentioned though, there's not really a need until sub-satoshi amounts have any real-world value.

I'm hoping that by the time we need more decimal places, 64 bit words will be the domain of obsolete sub-$1 microcontrollers driving the flashing eye LEDs in cheap import toys.

(And of course the low-cost bitcoin wallet - or secure wallet chip - that goes in everyone's cell phones.)

Companies claiming they got hacked and lost your coins sounds like fraud so perfect it could be called fashionable.  I never believe them.  If I ever experience the misfortune of a real intrusion, I declare I have been honest about the way I have managed the keys in Casascius Coins.  I maintain no ability to recover or reproduce the keys, not even under limitless duress or total intrusion.  Remember that trusting strangers with your coins without any recourse is, as a matter of principle, not a best practice.  Don't keep coins online. Use paper or hardware wallets instead.
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
December 22, 2012, 07:22:36 PM
 #15

Well there are other uses - colored coins, for example. A single satoshi could represent an entire asset type, for example, if sub-satoshi amounts were representable. It's not a very strong need though.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
2112
Legendary
*
Offline Offline

Activity: 2128
Merit: 1065



View Profile
December 22, 2012, 07:29:37 PM
 #16

Actually the fact that all bitcoins fit within 2**53 is quite a happy accident. It means that integer-satoshi amounts can be represented exactly by the IEEE decimal64 type, which provides one route towards practically infinite divisibility by using exact arbitrary-precision rational arithmetic and decimal64 for serialization.
Yeah, definitely a fortuitous choice. It correctly fits in all three floating point formats: binary64 (a.k.a. double precision) and both representations of decimal64 (BID and DPD). 53-bit and 16-digit both happen to be quite broadly supported.

Use of decimal64 for serialization may not be a best choice, because of the two competing implementations are promoted, respectively, by Intel and IBM.

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
December 22, 2012, 09:00:20 PM
 #17

Yes, but without being partisan BID is the only format that really makes sense for this application. DPD is added complexity but allows easy conversion to BCD in hardware, for hardware accelerated decimal arithmetic. But being a financial application all internal arithmetic would have to be exact, arbitrary-precision rational rather than truncated floating point anyway, so the decimal64 format would only be used for serialization, making the hardware efficiency gains (and associated complexity) rather pointless.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
2112
Legendary
*
Offline Offline

Activity: 2128
Merit: 1065



View Profile
December 22, 2012, 09:26:28 PM
Last edit: December 22, 2012, 09:40:18 PM by 2112
 #18

Yes, but without being partisan BID is the only format that really makes sense for this application. DPD is added complexity but allows easy conversion to BCD in hardware, for hardware accelerated decimal arithmetic. But being a financial application all internal arithmetic would have to be exact, arbitrary-precision rational rather than truncated floating point anyway, so the decimal64 format would only be used for serialization, making the hardware efficiency gains (and associated complexity) rather pointless.
Well, you point of view depends on the point of sitting.

DPD is the only format with full support (from the vendor IBM) and has direct hardware acceleration (on POWER and z/Arch).

BID is the widest available (because of Intel), but has glaring omissions in support, e.g. no widely available implementations scanf() and printf(). It is no big task to write them looking at the IBM's code, but I would consider it dangerous to distribute such rewrite.

In my experience rational math is overrated for financial applications. Even very simple TVM calculations have irrational solutions. And you still may need to implement correct rounding just to properly interface with the outside world. And don't even mention the word "truncation". Smiley There is quite a few generaly accepted accounting procedures that are very explicit about the rounding mode and you'll have to match them in you rational math library to pass audits.

Edit: Also, one thing I forgot about rational math is that many people's expectations will not match the formal mathematical definitions. The most common example is 2 + 2 != 2 * 2. Mathematically this is false, but in practice you'll need to accomodate the old custom: 2.00 + 2.00 = 4.00, but 2.00 * 2.00 = 4.0000 .

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
December 22, 2012, 11:14:48 PM
 #19

Wouldn't a simpler system be to keep it as a 64bit unsigned integer value, increase the number of digits to 12 and put in place a limitation that no tx (or block can involve more than 10.5M BTC (50% of the money supply)?

2^64 = 1.84467E+19

10.5M BTC * 1E12 satoshis of precision per BTC = 1.05E19

You keep everything in bigint math, no need to go to a larger datatype (and thus larger tx size), no implementation issues with floats or decimals.  Simple & easy with the very minor limitation that a valid transaction can't have outputs or inputs valued at more than 10.5M BTC.  The limit is highly unlikely to be anything more than academic because Bitcoin is likely horribly flawed if a single entity has >50% of the money supply.

prezbo
Sr. Member
****
Offline Offline

Activity: 430
Merit: 250


View Profile
December 22, 2012, 11:50:49 PM
 #20

Wouldn't a simpler system be to keep it as a 64bit unsigned integer value, increase the number of digits to 12 and put in place a limitation that no tx (or block can involve more than 10.5M BTC (50% of the money supply)?

2^64 = 1.84467E+19

10.5M BTC * 1E12 satoshis of precision per BTC = 1.05E19

You keep everything in bigint math, no need to go to a larger datatype (and thus larger tx size), no implementation issues with floats or decimals.  Simple & easy with the very minor limitation that a valid transaction can't have outputs or inputs valued at more than 10.5M BTC.  The limit is highly unlikely to be anything more than academic because Bitcoin is likely horribly flawed if a single entity has >50% of the money supply.


I wonder why only 9 digits after the decimal have been used, when it could've been 11...
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!