php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
convert.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Niels Dossche <nielsdos@php.net> |
14 +----------------------------------------------------------------------+
15*/
16
17#include "private.h"
18
19#ifndef BCMATH_CONVERT_H
20#define BCMATH_CONVERT_H
21
22char *bc_copy_and_toggle_bcd(char *restrict dest, const char *source, const char *source_end);
23void bc_write_bcd_representation(uint32_t value, char *str);
25
26/*
27 * Converts bc_num to BC_VECTOR, going backwards from pointer n by the number of
28 * characters specified by len.
29 */
30static inline BC_VECTOR bc_partial_convert_to_vector(const char *n, size_t len)
31{
32 if (len == BC_VECTOR_SIZE) {
34 }
35
36 BC_VECTOR num = 0;
37 BC_VECTOR base = 1;
38
39 for (size_t i = 0; i < len; i++) {
40 num += *n * base;
41 base *= BASE;
42 n--;
43 }
44
45 return num;
46}
47
48static inline void bc_convert_to_vector(BC_VECTOR *n_vector, const char *nend, size_t nlen)
49{
50 size_t i = 0;
51 while (nlen > 0) {
52 size_t len = MIN(BC_VECTOR_SIZE, nlen);
53 n_vector[i] = bc_partial_convert_to_vector(nend, len);
54 nend -= len;
55 nlen -= len;
56 i++;
57 }
58}
59
60#endif
size_t len
Definition apprentice.c:174
#define BASE
Definition bcmath.h:63
void bc_write_bcd_representation(uint32_t value, char *str)
Definition convert.c:148
BC_VECTOR bc_parse_chunk_chars(const char *str)
char * bc_copy_and_toggle_bcd(char *restrict dest, const char *source, const char *source_end)
Definition convert.c:24
zend_long n
Definition ffi.c:4979
uint32_t BC_VECTOR
Definition private.h:52
#define BC_VECTOR_SIZE
Definition private.h:53
#define MIN(a, b)
value