Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-02 Thread Jason E. Aten
Thanks Michael!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3222a792-7008-4063-aece-8a2d9fd34fe1%40googlegroups.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Michael Jones
forgot the code...final test is what generates the report above.

float128.go: https://play.golang.org/p/2MzjllLC3qT
float128_test.go: https://play.golang.org/p/ZQwsFh0_Apt

On Sat, Feb 1, 2020 at 7:32 PM Michael Jones 
wrote:

> As promised, some careful results from one of the tests in my
> doubled-precision library.
>
> Rows are iteration's of Jean-Michel Muller's roundoff-intolerant Œ()
> function:
>
> http://perso.ens-lyon.fr/jean-michel.muller/
>
> Columns are 32-bit floating point,64-bit floating point, my fast 128-bit
> library, Go big float, and Go rationals (printed as float)
>
> Answers are good for a while, and then fail as they must. compare always
> to the right column.
>
> Also, Dr. Kahan on the topic -- always read his every word!
>
> How Futile are Mindless Assessments of Roundoff In Floating-Point
> Computation ?
> Professor W. Kahan
> § 5, page 14
> https://www.cs.berkeley.edu/~wkahan/Mindless.pdf
>
>
> === RUN   TestMuller
>   0:   4.0   4.00
> +4.000e+00 4.000
> 4.00…
>   1:   4.25000   4.25
> +4.250e+00 4.250
> 4.25…
>   2:   4.470588684   4.470588235294115975
> +4.4705882352941176470588235294117e+00 4.4705882352941176470588235294118
> 4.4705882352941176470588235294117647058823529411764705882352941176470588…
>   3:   4.644744873   4.644736842105217534
> +4.6447368421052631578947368421047e+00 4.6447368421052631578947368421053
> 4.6447368421052631578947368421052631578947368421052631578947368421052632…
>   4:   4.770706177   4.770538243625082941
> +4.7705382436260623229461756373816e+00 4.7705382436260623229461756373938
> 4.7705382436260623229461756373937677053824362606232294617563739376770538…
>   5:   4.859214783   4.855700712568562949
> +4.8557007125890736342042755341875e+00 4.8557007125890736342042755344418
> 4.8557007125890736342042755344418052256532066508313539192399049881235154…
>   6:   4.983123779   4.910847498660629640
> +4.9108474990827932004402592585550e+00 4.9108474990827932004402592637887
> 4.9108474990827932004402592637886755533814357343769108474990827932004403…
>   7:   6.395431519   4.945537395530507752
> +4.9455374041239167247733836966321e+00 4.9455374041239167247733838031676
> 4.9455374041239167247733838031676461798983962546070325729654348042633728…
>   8:  27.632629395   4.966962408040998866
> +4.9669625817627005987119363335665e+00 4.9669625817627005987119384872579
> 4.9669625817627005987119384872578590383346845054961655244646085209448470…
>   9:  86.993759155   4.980042204293013697
> +4.9800457013556311612685646399287e+00 4.9800457013556311612686079942904
> 4.9800457013556311612686079942903718963021236734644222853921922457735370…
>  10:  99.255508423   4.987909232795786352
> +4.9879794484783922601392624051427e+00 4.9879794484783922601401328939769
> 4.987979448478392260140132893976940072111033913186330660946103656976…
>  11:  99.962585449   4.991362641314552206
> +4.9927702880620680974721416957309e+00 4.9927702880620680974895925483283
> 4.9927702880620680974895925483282696604561239860070565468956074766812844…
>  12:  99.998130798   4.967455095552267608
> +4.9956558915066340262745164361610e+00 4.9956558915066340266240282615671
> 4.9956558915066340266240282615670560447223264138375322338595040105640829…
>  13:  99.08447   4.429690498308829660
> +4.9973912683813441058976817599037e+00 4.9973912683813441128938690216426
> 4.9973912683813441128938690216425944791795065582105346913888017869771418…
>  14: 100.0  -7.817236578459315410
> +4.9984339439448167790186456309858e+00 4.9984339439448169190138971781902
> 4.9984339439448169190138971781902382881448247682045125641413593279228615…
>  15: 100.0 168.939167671064581100
> +4.9990600719708910670530314075958e+00 4.9990600719708938678168396062869
> 4.9990600719708938678168396062869249162956010827138675312945769521384463…
>  16: 100.0 102.039963152059272034
> +4.9994359371467831224113039612204e+00 4.9994359371468391479978508864998
> 4.9994359371468391479978508864997899689960802031068986343509970885820809…
>  17: 100.0 100.099947516249699220
> +4.9996615241026469022949297281691e+00 4.9996615241037675377868879857271
> 4.9996615241037675377868879857270921122953326315959962489248369318086283…
>  18: 100.0 100.004992040972439327
> +4.9997969006910037174292363662054e+00 4.9997969007134179126629930746330
> 4.9997969007134179126629930746330014204806141590496819671038715851326606…
>  19: 100.0 100.000249579237305397
> +4.9998781350296295179302235821482e+00 4.9998781354779312492317320300204
> 4.9998781354779312492317320300204045157850179321411177471298083841044938…
>  20: 100.0 100.12478620163847
> +4.268705383513445350585201744e+00 4.268795045999044664529810255
> 

Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Michael Jones
As promised, some careful results from one of the tests in my
doubled-precision library.

Rows are iteration's of Jean-Michel Muller's roundoff-intolerant Œ()
function:

http://perso.ens-lyon.fr/jean-michel.muller/

Columns are 32-bit floating point,64-bit floating point, my fast 128-bit
library, Go big float, and Go rationals (printed as float)

Answers are good for a while, and then fail as they must. compare always to
the right column.

Also, Dr. Kahan on the topic -- always read his every word!

How Futile are Mindless Assessments of Roundoff In Floating-Point
Computation ?
Professor W. Kahan
§ 5, page 14
https://www.cs.berkeley.edu/~wkahan/Mindless.pdf


=== RUN   TestMuller
  0:   4.0   4.00
+4.000e+00 4.000
4.00…
  1:   4.25000   4.25
+4.250e+00 4.250
4.25…
  2:   4.470588684   4.470588235294115975
+4.4705882352941176470588235294117e+00 4.4705882352941176470588235294118
4.4705882352941176470588235294117647058823529411764705882352941176470588…
  3:   4.644744873   4.644736842105217534
+4.6447368421052631578947368421047e+00 4.6447368421052631578947368421053
4.6447368421052631578947368421052631578947368421052631578947368421052632…
  4:   4.770706177   4.770538243625082941
+4.7705382436260623229461756373816e+00 4.7705382436260623229461756373938
4.7705382436260623229461756373937677053824362606232294617563739376770538…
  5:   4.859214783   4.855700712568562949
+4.8557007125890736342042755341875e+00 4.8557007125890736342042755344418
4.8557007125890736342042755344418052256532066508313539192399049881235154…
  6:   4.983123779   4.910847498660629640
+4.9108474990827932004402592585550e+00 4.9108474990827932004402592637887
4.9108474990827932004402592637886755533814357343769108474990827932004403…
  7:   6.395431519   4.945537395530507752
+4.9455374041239167247733836966321e+00 4.9455374041239167247733838031676
4.9455374041239167247733838031676461798983962546070325729654348042633728…
  8:  27.632629395   4.966962408040998866
+4.9669625817627005987119363335665e+00 4.9669625817627005987119384872579
4.9669625817627005987119384872578590383346845054961655244646085209448470…
  9:  86.993759155   4.980042204293013697
+4.9800457013556311612685646399287e+00 4.9800457013556311612686079942904
4.9800457013556311612686079942903718963021236734644222853921922457735370…
 10:  99.255508423   4.987909232795786352
+4.9879794484783922601392624051427e+00 4.9879794484783922601401328939769
4.987979448478392260140132893976940072111033913186330660946103656976…
 11:  99.962585449   4.991362641314552206
+4.9927702880620680974721416957309e+00 4.9927702880620680974895925483283
4.9927702880620680974895925483282696604561239860070565468956074766812844…
 12:  99.998130798   4.967455095552267608
+4.9956558915066340262745164361610e+00 4.9956558915066340266240282615671
4.9956558915066340266240282615670560447223264138375322338595040105640829…
 13:  99.08447   4.429690498308829660
+4.9973912683813441058976817599037e+00 4.9973912683813441128938690216426
4.9973912683813441128938690216425944791795065582105346913888017869771418…
 14: 100.0  -7.817236578459315410
+4.9984339439448167790186456309858e+00 4.9984339439448169190138971781902
4.9984339439448169190138971781902382881448247682045125641413593279228615…
 15: 100.0 168.939167671064581100
+4.9990600719708910670530314075958e+00 4.9990600719708938678168396062869
4.9990600719708938678168396062869249162956010827138675312945769521384463…
 16: 100.0 102.039963152059272034
+4.9994359371467831224113039612204e+00 4.9994359371468391479978508864998
4.9994359371468391479978508864997899689960802031068986343509970885820809…
 17: 100.0 100.099947516249699220
+4.9996615241026469022949297281691e+00 4.9996615241037675377868879857271
4.9996615241037675377868879857270921122953326315959962489248369318086283…
 18: 100.0 100.004992040972439327
+4.9997969006910037174292363662054e+00 4.9997969007134179126629930746330
4.9997969007134179126629930746330014204806141590496819671038715851326606…
 19: 100.0 100.000249579237305397
+4.9998781350296295179302235821482e+00 4.9998781354779312492317320300204
4.9998781354779312492317320300204045157850179321411177471298083841044938…
 20: 100.0 100.12478620163847
+4.268705383513445350585201744e+00 4.268795045999044664529810255
4.268795045999044664529810255297667014507019629318651153480676099193…
 21: 100.0 100.00623921607712
+4.559477336189227766623157740e+00 4.561270611577381190152822945
4.561270611577381190152822944886054388799381889725655444194135741792…
 22: 100.0 100.00031195796169
+4.700894239992550386653856177e+00 4.736760057124445790151493568

Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Jason E. Aten
I appreciate the sophisticated and math conscious discussion here.

For those reading this thread in the future, I note the state of the art in 
Go at the moment seems to be this
arbitrary precision decimal library created by the CockroachDB guys for APD 
standard/postgresql conformance.
Note that arbitrary doesn't mean infinite, it means you can pick the 
precision your application needs.

https://github.com/cockroachdb/apd

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/dde824b9-f200-43df-8461-1d5fc26c1cce%40googlegroups.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Michael Jones
Your expectations are wrong in the sense of being overly optimistic.

This is a chaotic attractor, under any form of rounding or precision it
will “fail” in the way you mean (and “succeed” in proving the power of a
strong attractor!)

I have this as a test at home that does each step in 32, 64, doubled
precision (~120 bit fp at 1/4 of full speed), and big. I’ll send it later
today.

No matter what you choose to do, the chaotic attractor will win.

Michael

On Sat, Feb 1, 2020 at 2:02 PM  wrote:

> Perhaps I'm doing something wrong or using the library outside of its
> intended purpose, but I found that this library doesn't handle Muller's
> Recurrence correctly. For those not familiar, Muller's Recurrence is 108
> - (815-1500/z)/y
>
> https://play.golang.org/p/sePTgjZzHeY
>
> See
> https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/
>
> On Sunday, January 26, 2020 at 8:46:16 AM UTC-8, Robert Engels wrote:
>>
>> Which is exactly what github.com/robaho/fixed and many others do!
>>
>> On Jan 26, 2020, at 10:34 AM, Michael Jones  wrote:
>>
>> ...thus the virtue of scaled integers. scaling by 100 makes cents whole,
>> scaling by 1*100 gives four decimal places beyond that. There is
>> nothing bad about floating point despite the reputation, it's just not the
>> number system from algebra; nor is binary floating point the same as
>> decimal floating point. The problems all start with false presumptions.
>>
>> On Sun, Jan 26, 2020 at 8:20 AM Robert Engels 
>> wrote:
>>
>>> Just an FYI, often that is not correct. Many financial systems require
>>> fractional pennies due to the volume of transactions. Think about taxing
>>> stock exchanges the pennies add up quickly at any tax rate, so they use
>>> fractional pennies to reduce the size of the error bucket.
>>>
>>> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
>>>
>>> never use floating point if you are trying to represent money, say
>>> dollars and cents or decimal values of the euro.
>>> Store the money as integer number of pennies.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com
>>> 
>>> .
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com
>>> 
>>> .
>>>
>>
>>
>> --
>>
>> *Michael T. jonesmichae...@gmail.com*
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/46cadc14-9c8e-4c3a-9c6b-d0af7b621061%40googlegroups.com
> 
> .
>
-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQzsFhP%3DwxVwAkp38HyQWDEH7ys90XSm%2BLOe%3Dct5EwhV3w%40mail.gmail.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Manlio Perillo
Even if fixed supports 7 decimal places, those 7 decimal places should have 
the same value (after rounding) as the result provided by math.Big.
I suspect the precision loss is in the Div method: 
https://github.com/robaho/fixed/blob/master/fixed.go#L232


Manlio Perillo

On Sunday, February 2, 2020 at 12:11:08 AM UTC+1, Robert Engels wrote:
>
> fixed only supports 8 decimals places - fixed. Without digging into the 
> algorithm I’m sure that is the source of your issue. 
>
>
> On Feb 1, 2020, at 4:03 PM, crate...@gmail.com  wrote:
>
> 
> Perhaps I'm doing something wrong or using the library outside of its 
> intended purpose, but I found that this library doesn't handle Muller's 
> Recurrence correctly. For those not familiar, Muller's Recurrence is 108 
> - (815-1500/z)/y
>
> https://play.golang.org/p/sePTgjZzHeY
>
> See 
> https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/
>
> On Sunday, January 26, 2020 at 8:46:16 AM UTC-8, Robert Engels wrote:
>>
>> Which is exactly what github.com/robaho/fixed and many others do!
>>
>> On Jan 26, 2020, at 10:34 AM, Michael Jones  wrote:
>>
>> 
>> ...thus the virtue of scaled integers. scaling by 100 makes cents whole, 
>> scaling by 1*100 gives four decimal places beyond that. There is 
>> nothing bad about floating point despite the reputation, it's just not the 
>> number system from algebra; nor is binary floating point the same as 
>> decimal floating point. The problems all start with false presumptions.
>>
>> On Sun, Jan 26, 2020 at 8:20 AM Robert Engels  
>> wrote:
>>
>>> Just an FYI, often that is not correct. Many financial systems require 
>>> fractional pennies due to the volume of transactions. Think about taxing 
>>> stock exchanges the pennies add up quickly at any tax rate, so they use 
>>> fractional pennies to reduce the size of the error bucket. 
>>>
>>> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
>>>
>>> 
>>> never use floating point if you are trying to represent money, say 
>>> dollars and cents or decimal values of the euro.
>>> Store the money as integer number of pennies.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golan...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golan...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com
>>>  
>>> 
>>> .
>>>
>>
>>
>> -- 
>>
>> *Michael T. jonesmichae...@gmail.com*
>>
>> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golan...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/46cadc14-9c8e-4c3a-9c6b-d0af7b621061%40googlegroups.com
>  
> 
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7e232e7a-3177-4a8a-bbcb-7271e58110b3%40googlegroups.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread Robert Engels
fixed only supports 8 decimals places - fixed. Without digging into the 
algorithm I’m sure that is the source of your issue. 


> On Feb 1, 2020, at 4:03 PM, craterm...@gmail.com wrote:
> 
> 
> Perhaps I'm doing something wrong or using the library outside of its 
> intended purpose, but I found that this library doesn't handle Muller's 
> Recurrence correctly. For those not familiar, Muller's Recurrence is 108 - 
> (815-1500/z)/y
> 
> https://play.golang.org/p/sePTgjZzHeY
> 
> See https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/
> 
>> On Sunday, January 26, 2020 at 8:46:16 AM UTC-8, Robert Engels wrote:
>> Which is exactly what github.com/robaho/fixed and many others do!
>> 
 On Jan 26, 2020, at 10:34 AM, Michael Jones  wrote:
 
>>> 
>>> ...thus the virtue of scaled integers. scaling by 100 makes cents whole, 
>>> scaling by 1*100 gives four decimal places beyond that. There is 
>>> nothing bad about floating point despite the reputation, it's just not the 
>>> number system from algebra; nor is binary floating point the same as 
>>> decimal floating point. The problems all start with false presumptions.
>>> 
 On Sun, Jan 26, 2020 at 8:20 AM Robert Engels  wrote:
 Just an FYI, often that is not correct. Many financial systems require 
 fractional pennies due to the volume of transactions. Think about taxing 
 stock exchanges the pennies add up quickly at any tax rate, so they 
 use fractional pennies to reduce the size of the error bucket. 
 
>> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
>> 
> 
> never use floating point if you are trying to represent money, say 
> dollars and cents or decimal values of the euro.
> Store the money as integer number of pennies.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golan...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 "golang-nuts" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to golan...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com.
>>> 
>>> 
>>> -- 
>>> Michael T. Jones
>>> michae...@gmail.com
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/46cadc14-9c8e-4c3a-9c6b-d0af7b621061%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/F99914BF-7D69-4CEF-9C00-B583615B44AD%40ix.netcom.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-02-01 Thread cratermoon
Perhaps I'm doing something wrong or using the library outside of its 
intended purpose, but I found that this library doesn't handle Muller's 
Recurrence correctly. For those not familiar, Muller's Recurrence is 108 - 
(815-1500/z)/y

https://play.golang.org/p/sePTgjZzHeY

See 
https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/

On Sunday, January 26, 2020 at 8:46:16 AM UTC-8, Robert Engels wrote:
>
> Which is exactly what github.com/robaho/fixed and many others do!
>
> On Jan 26, 2020, at 10:34 AM, Michael Jones  > wrote:
>
> 
> ...thus the virtue of scaled integers. scaling by 100 makes cents whole, 
> scaling by 1*100 gives four decimal places beyond that. There is 
> nothing bad about floating point despite the reputation, it's just not the 
> number system from algebra; nor is binary floating point the same as 
> decimal floating point. The problems all start with false presumptions.
>
> On Sun, Jan 26, 2020 at 8:20 AM Robert Engels  > wrote:
>
>> Just an FYI, often that is not correct. Many financial systems require 
>> fractional pennies due to the volume of transactions. Think about taxing 
>> stock exchanges the pennies add up quickly at any tax rate, so they use 
>> fractional pennies to reduce the size of the error bucket. 
>>
>> On Jan 26, 2020, at 8:50 AM, Pat Farrell > 
>> wrote:
>>
>> 
>> never use floating point if you are trying to represent money, say 
>> dollars and cents or decimal values of the euro.
>> Store the money as integer number of pennies.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com
>>  
>> 
>> .
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com
>>  
>> 
>> .
>>
>
>
> -- 
>
> *Michael T. jonesmichae...@gmail.com *
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/46cadc14-9c8e-4c3a-9c6b-d0af7b621061%40googlegroups.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-01-26 Thread Robert Engels
Which is exactly what github.com/robaho/fixed and many others do!

> On Jan 26, 2020, at 10:34 AM, Michael Jones  wrote:
> 
> 
> ...thus the virtue of scaled integers. scaling by 100 makes cents whole, 
> scaling by 1*100 gives four decimal places beyond that. There is nothing 
> bad about floating point despite the reputation, it's just not the number 
> system from algebra; nor is binary floating point the same as decimal 
> floating point. The problems all start with false presumptions.
> 
>> On Sun, Jan 26, 2020 at 8:20 AM Robert Engels  wrote:
>> Just an FYI, often that is not correct. Many financial systems require 
>> fractional pennies due to the volume of transactions. Think about taxing 
>> stock exchanges the pennies add up quickly at any tax rate, so they use 
>> fractional pennies to reduce the size of the error bucket. 
>> 
 On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
 
>>> 
>>> never use floating point if you are trying to represent money, say dollars 
>>> and cents or decimal values of the euro.
>>> Store the money as integer number of pennies.
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to golang-nuts+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com.
> 
> 
> -- 
> Michael T. Jones
> michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20AC2C62-3898-420C-805E-5A435CBF4391%40ix.netcom.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-01-26 Thread Michael Jones
...thus the virtue of scaled integers. scaling by 100 makes cents whole,
scaling by 1*100 gives four decimal places beyond that. There is
nothing bad about floating point despite the reputation, it's just not the
number system from algebra; nor is binary floating point the same as
decimal floating point. The problems all start with false presumptions.

On Sun, Jan 26, 2020 at 8:20 AM Robert Engels  wrote:

> Just an FYI, often that is not correct. Many financial systems require
> fractional pennies due to the volume of transactions. Think about taxing
> stock exchanges the pennies add up quickly at any tax rate, so they use
> fractional pennies to reduce the size of the error bucket.
>
> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
>
> 
> never use floating point if you are trying to represent money, say dollars
> and cents or decimal values of the euro.
> Store the money as integer number of pennies.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com
> 
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com
> 
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQy7m4-%3DJVQHpGf-kmH3T13gYQGe4%3DGd4%2BBBQT1pGtFDpA%40mail.gmail.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-01-26 Thread 温博格
And from Wikipedia on the Vancouver Stock Exchange.
"The history of the exchange's index provides a standard case example of
large errors  arising from
seemingly innocuous floating point calculations. In January 1982 the index
was initialized at 1000 and subsequently updated and truncated
 to three decimal places on each
trade. Such a thing was done about 3000 times each day. The accumulated
truncations led to an erroneous loss of around 25 points per month. Over
the weekend of November 25–28, 1983, the error was corrected, raising the
value of the index from its Friday closing figure of 524.811 to 1098.892"

On Sun, Jan 26, 2020 at 11:20 AM Robert Engels 
wrote:

> Just an FYI, often that is not correct. Many financial systems require
> fractional pennies due to the volume of transactions. Think about taxing
> stock exchanges the pennies add up quickly at any tax rate, so they use
> fractional pennies to reduce the size of the error bucket.
>
> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
>
> 
> never use floating point if you are trying to represent money, say dollars
> and cents or decimal values of the euro.
> Store the money as integer number of pennies.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com
> 
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOUkXSptfibw5D4UqwORhZLH8%2BV9s24Os-SjSp5RH2OLUN%2Bn1g%40mail.gmail.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-01-26 Thread Robert Engels
Just an FYI, often that is not correct. Many financial systems require 
fractional pennies due to the volume of transactions. Think about taxing stock 
exchanges the pennies add up quickly at any tax rate, so they use 
fractional pennies to reduce the size of the error bucket. 

> On Jan 26, 2020, at 8:50 AM, Pat Farrell  wrote:
> 
> 
> never use floating point if you are trying to represent money, say dollars 
> and cents or decimal values of the euro.
> Store the money as integer number of pennies.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/AF9827F5-C849-4F4E-8229-005D6C9A0E03%40ix.netcom.com.


[go-nuts] Re: keep just 2 decimal places in a float64

2020-01-26 Thread Pat Farrell
never use floating point if you are trying to represent money, say dollars 
and cents or decimal values of the euro.
Store the money as integer number of pennies.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cc852ce3-6f88-40fd-8b19-877c76deec10%40googlegroups.com.


Re: [go-nuts] Re: keep just 2 decimal places in a float64

2020-01-25 Thread Kurtis Rader
On Sat, Jan 25, 2020 at 9:26 PM  wrote:

> Floating point math has many pitfalls.
> https://play.golang.org/p/LK0lla8hM9w See also
> https://0.30004.com/
>

I was not aware of URL https://0.30004.com/. Like the XY
problem URL, http://xyproblem.info/, the URL you cited is another one to
remember to cite when a FAQ about floating point values occurs :-)

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-MhGVGup20mTFs3K%3DVBmOCMrx_TuT1ddmac2m%2BjVNZCw%40mail.gmail.com.


[go-nuts] Re: keep just 2 decimal places in a float64

2020-01-25 Thread cratermoon
Floating point math has many 
pitfalls.  https://play.golang.org/p/LK0lla8hM9w See also 
https://0.30004.com/

s

On Saturday, January 25, 2020 at 7:14:15 PM UTC-8, Jason E. Aten wrote:
>
>
> https://play.golang.org/p/87bDubJxjHO
>
> I'd like to truncate a float64 to just 2 decimal places (in base 10), but 
> math.Trunc is not helping me here... ideally I put 0.29 in and I get 0.29 
> out.
> Suggestions?  Playground examples appreciated.
>
> package main
>
> import (
> "fmt"
> "math"
> )
>
> // truncate off everything after the last two decimals, no rounding.
> func decimal2(x float64) float64 {
> return math.Trunc(x*100) / 100
> }
>
> func main() {
> x := 0.29
> y := decimal2(x)
> fmt.Printf("x=%v -> y = %v", x, y) // prints x=0.29  ->  y=0.28
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d3250e2a-e72d-40e5-987c-b9f5012dd3cc%40googlegroups.com.