diff options
author | Petri Savolainen <petri.savolainen@nokia.com> | 2021-03-04 16:49:49 +0200 |
---|---|---|
committer | Petri Savolainen <petri.savolainen@nokia.com> | 2021-06-22 15:09:54 +0300 |
commit | 9d370488150482a1965692e5c88d6a357c28c294 (patch) | |
tree | 476abd55fab2cdaa8afbca76970574cc2e51dba3 /include/odp/api/spec/std_types.h | |
parent | e7651465784f379e12b6b8c259a0fd49a1e5335f (diff) |
api: std_types: add fractional number type
Added odp_fract_u64_t type which can be used to define
fractional numbers accurately. A fractional to double
conversion function was added to help with this typical
conversion.
Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com>
Reviewed-by: Jere Leppänen <jere.leppanen@nokia.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
Diffstat (limited to 'include/odp/api/spec/std_types.h')
-rw-r--r-- | include/odp/api/spec/std_types.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/odp/api/spec/std_types.h b/include/odp/api/spec/std_types.h index bf3eb77a6..4b2af87ef 100644 --- a/include/odp/api/spec/std_types.h +++ b/include/odp/api/spec/std_types.h @@ -1,5 +1,6 @@ /* Copyright (c) 2013-2018, Linaro Limited * Copyright (c) 2021, ARM Limited + * Copyright (c) 2021, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -74,6 +75,39 @@ typedef struct ODP_ALIGNED(16) odp_u128_s { } odp_u128_t; /** + * Unsigned 64 bit fractional number + * + * The number is composed of integer and fraction parts. The fraction part is composed of + * two terms: numerator and denominator. Value of the number is sum of the integer and fraction + * parts: value = integer + numer/denom. When the fraction part is zero, the numerator is zero and + * the denominator may be zero. + */ +typedef struct odp_fract_u64_t { + /** Integer part */ + uint64_t integer; + + /** Numerator of the fraction part */ + uint64_t numer; + + /** Denominator of the fraction part. This may be zero when the numerator + * is zero. */ + uint64_t denom; + +} odp_fract_u64_t; + +/** + * Convert fractional number (u64) to double + * + * Converts value of the unsigned 64 bit fractional number to a double-precision + * floating-point value. + * + * @param fract Pointer to a fractional number + * + * @return Value of the fractional number as double + */ +double odp_fract_u64_to_dbl(const odp_fract_u64_t *fract); + +/** * @} */ |