For financial programs you may want to consider fixed point decimal values 
rather than floats.  In simple terms, rather than using floating point units of 
currency, you use integers for the smallest acceptable quantity.  This might 
be, for example, using an int to say how many pennies are involved and then 
dividing by 100 when you want to display dollars.  This would be fixed point 
decimal with two decimal places.

I often think of time durations as a fixed point decimal number of seconds with 
9 decimal places (nanoseconds).

    -Paul

> On Aug 30, 2018, at 8:27 AM, Marvin Renich <m...@renich.org> wrote:
> 
> * José Colón <jec....@gmail.com> [180830 06:53]:
>> Very interesting. So would it be a good idea to use these types of untyped 
>> constant calculations for financial applications, or instances where one 
>> would use the math.big package?
> 
> Not likely.  You would have to know at compile time the exact values you
> wanted to calculate, so you might as well not even write the program!
> 
> If you are writing financial applications or other applications where
> rounding and/or precision are important, you must have a much more
> thorough understanding of how the computer stores floating point values,
> how calculations are performed, how results are represented in the
> precision available, and how (and why) those results differ from the
> exact values.
> 
> Simply learning that Java and Python have rounding errors and that using
> Go's untyped constants give you the "human expected" results for some
> simple examples is woefully insufficient to write correct floating point
> code when such details are important.
> 
> On the other hand, there is a wide variety of programs that use floating
> point values that don't need to worry about the rounding error in the
> least significant bits.
> 
> As an example, if you had a set of coordinates, stored as floating point
> numbers, representing a graphical figure, it is highly probable that you
> could translate and scale those coordinates for display on the screen
> without worrying about, or having a deep understanding of, rounding
> errors.
> 
> ...Marvin
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to