Replies: 2 comments
-
Hi @mrflip! The documentation provides a userland example of how to implement an Regarding |
Beta Was this translation helpful? Give feedback.
-
Wow the implementation to enable that addMany snippet is elegant. Yes that works for me. Here's my question on the sumProduct -- is a naive solution at all dangerous, assuming intermediate numbers never leave the safe integer regime? let's say a customer orders 3.4 furlongs of frillery at $4.7770/furlong, 1.79 drams of drambuie at $3.3330/dram, and 19 thimbles at $2/thimble, will
(would be redone as a reduce and native-only) carry any risk of truncation, or would it be more accurate to carry out the full calculation before re-converting to a dinero object? I know enough to be nervous about all that but not enough to know what is/isn't dangerous. If it is dangerous, I believe it should be added, but if not, documenting it as a userland function would be the way to go. |
Beta Was this translation helpful? Give feedback.
-
We would like to be able to call a built-in method sum an iterable of dinero objects, rather than doing sequential binary additions externally -- eg when summing all the line item prices in a purchase order. Part of this is for convenience and pulling all the sensible error checks into the library, but also I get the creepy-crawlies when I see repeated additions of large numbers.
sum(addends: Iterable<price: Dinero>)
method to the API?sumProduct(Iterable<[price: Dinero, multiplier: number]>)
method that would sum the product of each price with the paired multiplier (as you would on a purchase order)?I believe it is safe to just do these with repeated calls to the outward-facing
add
,multiply
etc methods, but please give any implementation advice you have to offer. (Illustrating the point that the key virtue of these methods is to take customers of the library from "I belieeeeeve it is safe to just do these with repeated calls" to "I know that my calculations are correct, because Dinero is doing the work")Beta Was this translation helpful? Give feedback.
All reactions