tarantool / tarantool/doc

Add conversion between `box_decimal_t` and scaled integer

Open
#5,214 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
15
Forks
49
Avg merge
1d 13h
Merged PRs (30d)
3

Description

These are functions to convert between box_decimal_t and integers with
scale. Scale is a negated exponent. For example decimal 1.23 will be
converted to integer 123 if scale is 2 and to 1230 if scale is 3.

For API details check comments for next functions in
src/box/decimal.h.

API_EXPORT box_decimal_t *
box_decimal_scale_from_int32(box_decimal_t *dec, int32_t value, int scale);

API_EXPORT box_decimal_t *
box_decimal_scale_from_int64(box_decimal_t *dec, int64_t value, int scale);

API_EXPORT box_decimal_t *
box_decimal_scale_from_int128(box_decimal_t *dec, const uint64_t *value,
			      int scale);
API_EXPORT box_decimal_t *
box_decimal_scale_from_int256(box_decimal_t *dec, const uint64_t *value,
			      int scale);

API_EXPORT const box_decimal_t *
box_decimal_scale_to_int32(const box_decimal_t *dec, int scale, int32_t *value);

API_EXPORT const box_decimal_t *
box_decimal_scale_to_int64(const box_decimal_t *dec, int scale, int64_t *value);

API_EXPORT const box_decimal_t *
box_decimal_scale_to_int128(const box_decimal_t *dec, int scale,
			    uint64_t *value);

API_EXPORT const box_decimal_t *
box_decimal_scale_to_int256(const box_decimal_t *dec, int scale,
			    uint64_t *value);

Requested by @nshy in https://github.com/tarantool/tarantool/commit/922eb0ce08e6382a6931cd74dd2384c61d5ee6cb.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the comments for the listed functions in src/box/decimal.h and compare their signatures with existing documentation in this repository. Document the int32, int64, int128, and int256 conversions, including the negated-exponent scale behavior and both directions; done when all eight APIs and the 1.23 example are clearly covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.