Click here to Skip to main content
15,887,135 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:07
professionalJeremy Falcon23-Mar-24 5:07 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
charlieg22-Mar-24 8:46
charlieg22-Mar-24 8:46 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:09
professionalJeremy Falcon23-Mar-24 5:09 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
#realJSOP22-Mar-24 10:16
mve#realJSOP22-Mar-24 10:16 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:11
professionalJeremy Falcon23-Mar-24 5:11 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
#realJSOP24-Mar-24 11:54
mve#realJSOP24-Mar-24 11:54 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:42
professionalJeremy Falcon26-Mar-24 10:42 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
rjmoses23-Mar-24 0:00
professionalrjmoses23-Mar-24 0:00 
It will largely depend on your application and requirements.

For currency type applications, consider using a BCD (Binary Code Decimal, used in COBOL) package. See below for references.

For integer type applications, there are a few "large" int packages.

For scientific applications, there are a number of packages for large number processing.

************ BCD references ********************

https://web.archive.org/web/20081102170717/http://webster.cs.ucr.edu/AoA/Windows/HTML/AdvancedArithmetica6.html#1000255

https://handwiki.org/wiki/Binary-coded_decimal#EBCDIC_zoned_decimal_conversion_table

Notes:
1) BCD numbers can be packed (2 digits/byte) or unpacked (1 digit per byte)
2) The low order byte (right most) of packed is nnnnssss where nnnn is the low order digit and ssss is the sign (0x0D for negative, 0x0F for positive)
3) The spec is (www,ddd) where www is the total bytes and ddd is the digits to right of decimal point. E.g.: 5,2 is a 5 digit number with 2 digits to the right of the decimal point--"123.45" This field would require 3 bytes packed, 6 bytes unpacked.
4) From IBM: For a field or array element of length N, if the PACKEVEN keyword is not specified, the number of digits is 2N - 1; if the PACKEVEN keyword is specified, the number of digits is 2(N-1).
5) Some documentation refers to BCD as DECIMAL but others use DECIMAL to refer to floating point.

********************* For large int ********************

Microsoft SafeInt package

SafeInt Class | Microsoft Learn[^]

The decNumber package can handle decimal integer number of user defined precision

GitHub - dnotq/decNumber: Decimal Floating Point decNumber C Library by IBM Fellow Mike Cowlishaw[^]

(I have not yet used or investigate the cran project.)

CRAN - Package VeryLargeIntegers[^]

******************** For Floating Point ********************


Floating point gets very complex and confusing because there has never been a really good, consistent standard for floating point. Most conventions are vendor/system design dependent.

Here's a list of packages and some brief explanations:

GCC stores and performs operations on a variable defined as long double as fp80 (10 bytes), but 16 bytes are used.


General reference: https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software
https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

GCC Floating point: https://gcc.gnu.org/onlinedocs/gcc/extensions-to-the-c-language-family/additional-floating-types.html

Floating point specifications: https://speleotrove.com/decimal/dbspec.html
Performance specs: https://speleotrove.com/decimal/dpquad.html
http://speleotrove.com/decimal/decbits.html

IBM decimal arithmetic package: https://github.com/hercules-390/decNumber-icu-368

Half precision: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
Half precision software (16 bit) https://half.sourceforge.net/


Comparison BID vs DFP:
1) https://www.researchgate.net/publication/224114304_Performance_analysis_of_decimal_floating-point_libraries_and_its_impact_on_decimal_hardware_and_software_solutions

2) http://iccd.et.tudelft.nl/Proceedings/2007/Papers/3.3.1.pdf

3) libdpf source: https://github.com/libdfp/libdfp

---------------------------------------------------------------------------------------------

-----------------16 bit (half) -------------------------------------
The IEEE 754 standard[9] specifies a binary16 as having the following format:

* Sign bit: 1 bit
* Exponent width: 5 bits
* Significand precision: 11 bits (10 explicitly stored)

The format is laid out as follows:

The format is assumed to have an implicit lead bit with value 1 unless the exponent field is stored with all zeros. Thus, only 10 bits of the significand appear in the memory format but the total precision is 11 bits. In IEEE 754 parlance, there are 10 bits of significand, but there are 11 bits of significand precision (log10(211) ≈ 3.311 decimal digits, or 4 digits ± slightly less than 5 units in the last place).
-------------------------------32 bit format -----------------------------------------------------
https://en.wikipedia.org/wiki/Single-precision_floating-point_format


-------------------------------64 bit format -----------------------------------------------------

https://en.wikipedia.org/wiki/Double-precision_floating-point_format


------------------------------80 bit format--------------------------------------------------------

https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format

--------------------IBM HFP-------------------------------
https://en.wikipedia.org/wiki/IBM_hexadecimal_floating-point


------------------------------96 bit format--------------------------------------------------------

96 bit FP occupies 128 bits in x86 platforms

The Motorola 6888x math coprocessors and the Motorola 68040 and 68060 processors support this same 64-bit significand extended precision type (similar to the Intel format although padded to a 96-bit format with 16 unused bits inserted between the exponent and significand fields[9]). The follow-on Coldfire processors do not support this 96-bit extended precision format.[10]
The FPA10 math coprocessor for early ARM processors also supports this extended precision type (similar to the Intel format although padded to a 96-bit format with 16 zero bits inserted between the sign and the exponent fields), but without correct rounding.
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:15
professionalJeremy Falcon23-Mar-24 5:15 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
charlieg31-Mar-24 4:31
charlieg31-Mar-24 4:31 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Stacy Dudovitz23-Mar-24 13:41
professionalStacy Dudovitz23-Mar-24 13:41 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon24-Mar-24 4:47
professionalJeremy Falcon24-Mar-24 4:47 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Stacy Dudovitz24-Mar-24 15:59
professionalStacy Dudovitz24-Mar-24 15:59 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:41
professionalJeremy Falcon26-Mar-24 10:41 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
mdblack9825-Mar-24 3:13
mdblack9825-Mar-24 3:13 
GeneralWordle 1,006 Pin
StarNamer@work20-Mar-24 14:04
professionalStarNamer@work20-Mar-24 14:04 
GeneralRe: Wordle 1,006 Pin
Amarnath S20-Mar-24 14:08
professionalAmarnath S20-Mar-24 14:08 
GeneralRe: Wordle 1,006 Pin
Sandeep Mewara20-Mar-24 15:42
mveSandeep Mewara20-Mar-24 15:42 
GeneralRe: Wordle 1,006 Pin
Shane010320-Mar-24 17:51
Shane010320-Mar-24 17:51 
GeneralRe: Wordle 1,006 (3/6) Pin
Jeremy Falcon20-Mar-24 19:19
professionalJeremy Falcon20-Mar-24 19:19 
GeneralRe: Wordle 1,006 Pin
GKP199220-Mar-24 19:22
professionalGKP199220-Mar-24 19:22 
GeneralRe: Wordle 1,006 Pin
OriginalGriff20-Mar-24 20:06
mveOriginalGriff20-Mar-24 20:06 
GeneralRe: Wordle 1,006 - 4 4 me Pin
pkfox20-Mar-24 22:15
professionalpkfox20-Mar-24 22:15 
GeneralRe: Wordle 1,006 Pin
Sander Rossel20-Mar-24 22:25
professionalSander Rossel20-Mar-24 22:25 
GeneralRe: Wordle 1,006 Pin
ChandraRam20-Mar-24 23:23
ChandraRam20-Mar-24 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.