**diff options**

author | Christian Grothoff <christian@grothoff.org> | 2021-07-10 14:52:59 +0200 |
---|---|---|

committer | Christian Grothoff <christian@grothoff.org> | 2021-07-10 14:55:35 +0200 |

commit | 249ba03c36d6bc61b78bdd5a7f1ca55701f1c287 (patch) | |

tree | 4bb49f6defd74b77b9eed0622c74f41749301717 /src/include | |

parent | 883b1fc70bc84bb053d09b5eab921f24134194b9 (diff) | |

download | exchange-249ba03c36d6bc61b78bdd5a7f1ca55701f1c287.tar.gz exchange-249ba03c36d6bc61b78bdd5a7f1ca55701f1c287.tar.bz2 exchange-249ba03c36d6bc61b78bdd5a7f1ca55701f1c287.zip |

expose 2^52 amount value limit in header, check that limit in test cases, add TALER_amount_multiply and TALER_amount_divide2 operations

Diffstat (limited to 'src/include')

-rw-r--r-- | src/include/taler_amount_lib.h | 31 |

1 files changed, 31 insertions, 0 deletions

diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h index 7a0b299c..5defc37e 100644 --- a/src/include/taler_amount_lib.h +++ b/src/include/taler_amount_lib.h @@ -64,6 +64,11 @@ extern "C" */ #define TALER_AMOUNT_FRAC_LEN 8 +/** + * Maximum legal 'value' for an amount, based on IEEE double (for JavaScript compatibility). + */ +#define TALER_AMOUNT_MAX_VALUE (1LLU << 52) + GNUNET_NETWORK_STRUCT_BEGIN @@ -332,6 +337,32 @@ TALER_amount_divide (struct TALER_Amount *result, const struct TALER_Amount *dividend, uint32_t divisor); +/** + * Divide one amount by another. Note that this function + * may introduce a rounding error. It rounds down. + * + * @param dividend amount to divide + * @param divisor by what to divide, must be positive + * @return @a dividend / @a divisor, rounded down. -1 on currency missmatch, + * INT_MAX for division by zero + */ +int +TALER_amount_divide2 (const struct TALER_Amount *dividend, + const struct TALER_Amount *divisor); + + +/** + * Multiply an @a amount by a @ factor. + * + * @param[out] result where to store @a amount * @a factor + * @param amount amount to multiply + * @param factor factor by which to multiply + */ +enum TALER_AmountArithmeticResult +TALER_amount_multiply (struct TALER_Amount *result, + const struct TALER_Amount *amount, + uint32_t factor); + /** * Normalize the given amount. |