▲ 464 ▼ IEEE 754 (cdn.fosstodon.org) submitted 2 years ago by bleistift2@sopuli.xyz to c/science_memes@mander.xyz 37 comments fedilink hide all child comments cross-posted from: https://lemmy.ml/post/24332731 Stolen Cross-posted from here: https://fosstodon.org/@foo/113731569632505985
[–] tdawg@lemmy.world 16 points 2 years ago (11 children) Please tell me you aren't using floating points with money permalink fedilink source parent hideshow 11 child comments replies: [–] wewbull@feddit.uk 39 points 2 years ago Knowing not to use floating point with money is good use of that knowledge. permalink fedilink source parent [–] psivchaz@reddthat.com 6 points 2 years ago You'd be dismayed to find out how often I've seen people do that. permalink fedilink source parent [–] zqwzzle@lemmy.ca 4 points 2 years ago (2 children) Yeah I shudder when I see floats and currency. permalink fedilink source parent hideshow 2 child comments replies: [–] Womble@lemmy.world 3 points 2 years ago* Eh, if you use doubles and you add 0.000314 (just over 0.03 cents) to ten billion dollars you have an error of 1/10000 of a cent, and thats a deliberately perverse transaction. Its not ideal but its not the waiting disaster that using single precision is. permalink fedilink source parent [–] SubArcticTundra@lemmy.ml 2 points 2 years ago* That sounds like an explosive duo permalink fedilink source parent [–] Saleh@feddit.org 2 points 2 years ago (5 children) How do you do money? Especially with stuff like some prices having three or four decimals permalink fedilink source parent hideshow 5 child comments replies: [–] jmcs@discuss.tchncs.de 10 points 2 years ago (4 children) Instead of representing $1.102 as 1.102 your store it as 1012 (or whatever precision you need) and divide by 1000 only for displaying it. permalink fedilink source parent hideshow 4 child comments replies: [–] Saleh@feddit.org 1 point 2 years ago (3 children) So if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for? permalink fedilink source parent hideshow 3 child comments replies: [–] jmcs@discuss.tchncs.de 6 points 2 years ago (1 child) It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won't need to implement it on your own outside of university exercises. permalink fedilink source parent hideshow 1 child comment replies: [–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent [–] wewbull@feddit.uk 5 points 2 years ago No exponent, or at least a common fixed exponent. The technique is called "fixed point" as opposed to "floating point". The rationale is always to have a known level of precision. permalink fedilink source parent
[–] wewbull@feddit.uk 39 points 2 years ago Knowing not to use floating point with money is good use of that knowledge. permalink fedilink source parent
[–] psivchaz@reddthat.com 6 points 2 years ago You'd be dismayed to find out how often I've seen people do that. permalink fedilink source parent
[–] zqwzzle@lemmy.ca 4 points 2 years ago (2 children) Yeah I shudder when I see floats and currency. permalink fedilink source parent hideshow 2 child comments replies: [–] Womble@lemmy.world 3 points 2 years ago* Eh, if you use doubles and you add 0.000314 (just over 0.03 cents) to ten billion dollars you have an error of 1/10000 of a cent, and thats a deliberately perverse transaction. Its not ideal but its not the waiting disaster that using single precision is. permalink fedilink source parent [–] SubArcticTundra@lemmy.ml 2 points 2 years ago* That sounds like an explosive duo permalink fedilink source parent
[–] Womble@lemmy.world 3 points 2 years ago* Eh, if you use doubles and you add 0.000314 (just over 0.03 cents) to ten billion dollars you have an error of 1/10000 of a cent, and thats a deliberately perverse transaction. Its not ideal but its not the waiting disaster that using single precision is. permalink fedilink source parent
[–] SubArcticTundra@lemmy.ml 2 points 2 years ago* That sounds like an explosive duo permalink fedilink source parent
[–] Saleh@feddit.org 2 points 2 years ago (5 children) How do you do money? Especially with stuff like some prices having three or four decimals permalink fedilink source parent hideshow 5 child comments replies: [–] jmcs@discuss.tchncs.de 10 points 2 years ago (4 children) Instead of representing $1.102 as 1.102 your store it as 1012 (or whatever precision you need) and divide by 1000 only for displaying it. permalink fedilink source parent hideshow 4 child comments replies: [–] Saleh@feddit.org 1 point 2 years ago (3 children) So if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for? permalink fedilink source parent hideshow 3 child comments replies: [–] jmcs@discuss.tchncs.de 6 points 2 years ago (1 child) It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won't need to implement it on your own outside of university exercises. permalink fedilink source parent hideshow 1 child comment replies: [–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent [–] wewbull@feddit.uk 5 points 2 years ago No exponent, or at least a common fixed exponent. The technique is called "fixed point" as opposed to "floating point". The rationale is always to have a known level of precision. permalink fedilink source parent
[–] jmcs@discuss.tchncs.de 10 points 2 years ago (4 children) Instead of representing $1.102 as 1.102 your store it as 1012 (or whatever precision you need) and divide by 1000 only for displaying it. permalink fedilink source parent hideshow 4 child comments replies: [–] Saleh@feddit.org 1 point 2 years ago (3 children) So if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for? permalink fedilink source parent hideshow 3 child comments replies: [–] jmcs@discuss.tchncs.de 6 points 2 years ago (1 child) It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won't need to implement it on your own outside of university exercises. permalink fedilink source parent hideshow 1 child comment replies: [–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent [–] wewbull@feddit.uk 5 points 2 years ago No exponent, or at least a common fixed exponent. The technique is called "fixed point" as opposed to "floating point". The rationale is always to have a known level of precision. permalink fedilink source parent
[–] Saleh@feddit.org 1 point 2 years ago (3 children) So if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for? permalink fedilink source parent hideshow 3 child comments replies: [–] jmcs@discuss.tchncs.de 6 points 2 years ago (1 child) It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won't need to implement it on your own outside of university exercises. permalink fedilink source parent hideshow 1 child comment replies: [–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent [–] wewbull@feddit.uk 5 points 2 years ago No exponent, or at least a common fixed exponent. The technique is called "fixed point" as opposed to "floating point". The rationale is always to have a known level of precision. permalink fedilink source parent
[–] jmcs@discuss.tchncs.de 6 points 2 years ago (1 child) It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won't need to implement it on your own outside of university exercises. permalink fedilink source parent hideshow 1 child comment replies: [–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent
[–] Saleh@feddit.org 2 points 2 years ago Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company. permalink fedilink source parent
[–] wewbull@feddit.uk 5 points 2 years ago No exponent, or at least a common fixed exponent. The technique is called "fixed point" as opposed to "floating point". The rationale is always to have a known level of precision. permalink fedilink source parent