Math Processor Unit Library

libmpu – library of arithmetic functions for integer, real, and complex numbers of increased digit capacity

16 Commits   0 Branches   2 Tags
41c271da (kx 2025-01-05 15:42:39 +0300   1) .TH iatoi 3  "December 27, 2024" "libmpu" "LibMPU Programmer's Manual"
41c271da (kx 2025-01-05 15:42:39 +0300   2) .SH NAME
41c271da (kx 2025-01-05 15:42:39 +0300   3) \fBiatoi\fP, \fBiatoui\fP \- functions for converting ASCII string to integer number
41c271da (kx 2025-01-05 15:42:39 +0300   4) .SH SYNOPSIS
41c271da (kx 2025-01-05 15:42:39 +0300   5) .nf
41c271da (kx 2025-01-05 15:42:39 +0300   6) .B #include <libmpu.h>
41c271da (kx 2025-01-05 15:42:39 +0300   7) .PP
41c271da (kx 2025-01-05 15:42:39 +0300   8) .BI "void iatoi( mpu_int *" c ", __mpu_char8_t *" str ", int " nb " );
41c271da (kx 2025-01-05 15:42:39 +0300   9) .BI "void iatoui( mpu_int *" c ", __mpu_char8_t *" str ", int " nb " );
41c271da (kx 2025-01-05 15:42:39 +0300  10) .fi
41c271da (kx 2025-01-05 15:42:39 +0300  11) .SH DESCRIPTION
41c271da (kx 2025-01-05 15:42:39 +0300  12) The \fBiatoi()\fP, \fBiatoui()\fP functions are used to convert an ASCII string into numeric form.
41c271da (kx 2025-01-05 15:42:39 +0300  13) In the case of \fBiatoi()\fP function, the \fBstr\fP argument is considered as a pointer to a character
41c271da (kx 2025-01-05 15:42:39 +0300  14) array containing characters of a signed integer; in the case of \fBiatoui()\fP function, it is assumed
41c271da (kx 2025-01-05 15:42:39 +0300  15) that the string contains a representation of an unsigned integer type numeric constant.
41c271da (kx 2025-01-05 15:42:39 +0300  16) .PP
41c271da (kx 2025-01-05 15:42:39 +0300  17) Numeric constants in a string can be represented as binary, octal, hexadecimal, and decimal numbers.
41c271da (kx 2025-01-05 15:42:39 +0300  18) Binary numbers begin with the prefix \fB0b\fP or \fB0B\fP, for example, \fB0b1011\fP. The octal numbers
41c271da (kx 2025-01-05 15:42:39 +0300  19) must begin with '0' and contain digits from '0' through '7'. Hexadecimal constants begin with the prefix
41c271da (kx 2025-01-05 15:42:39 +0300  20) \fB0x\fP or \fB0X\fP and can contain characters from '0' to '7' and characters from 'a' to 'f' in any case.
41c271da (kx 2025-01-05 15:42:39 +0300  21) Decimal constants can contain characters from '0' to '9' but must not start with '0'. Before a number
41c271da (kx 2025-01-05 15:42:39 +0300  22) signs '+', '-' are allowed. If a string contains a binary, octal or hexadecimal constant, the sign
41c271da (kx 2025-01-05 15:42:39 +0300  23) is ignored.
41c271da (kx 2025-01-05 15:42:39 +0300  24) .PP
41c271da (kx 2025-01-05 15:42:39 +0300  25) The result is placed at \fBc\fP, and the parameter \fBnb\fP represents the size of the result \fBc\fP
41c271da (kx 2025-01-05 15:42:39 +0300  26) in bytes.
41c271da (kx 2025-01-05 15:42:39 +0300  27) .PP
41c271da (kx 2025-01-05 15:42:39 +0300  28) If the number represented in the \fBstr\fP string does not fit into the specified (\fBnb\fP) format, the
41c271da (kx 2025-01-05 15:42:39 +0300  29) overflow flag (\fBO\fP) is set.
41c271da (kx 2025-01-05 15:42:39 +0300  30) .PP
41c271da (kx 2025-01-05 15:42:39 +0300  31) The function affects the flags \fBA\fP, \fBC\fP, \fBO\fP, \fBP\fP, \fBS\fP, \fBZ\fP. Flags \fBA\fP, \fBC\fP
41c271da (kx 2025-01-05 15:42:39 +0300  32) flags are reset to 0. The flag \fBR\fP is not changed.
41c271da (kx 2025-01-05 15:42:39 +0300  33) .sp
41c271da (kx 2025-01-05 15:42:39 +0300  34) .SH EXAMPLES
41c271da (kx 2025-01-05 15:42:39 +0300  35) .nf
41c271da (kx 2025-01-05 15:42:39 +0300  36) .sp
41c271da (kx 2025-01-05 15:42:39 +0300  37) #include <libmpu.h>
41c271da (kx 2025-01-05 15:42:39 +0300  38) #include <stdio.h>
41c271da (kx 2025-01-05 15:42:39 +0300  39) 
41c271da (kx 2025-01-05 15:42:39 +0300  40) int main( void )
41c271da (kx 2025-01-05 15:42:39 +0300  41) {
41c271da (kx 2025-01-05 15:42:39 +0300  42)   int  rc = 0;
41c271da (kx 2025-01-05 15:42:39 +0300  43) 
41c271da (kx 2025-01-05 15:42:39 +0300  44)   __mpu_init();
41c271da (kx 2025-01-05 15:42:39 +0300  45)   __mpu_extra_warnings = 1;
41c271da (kx 2025-01-05 15:42:39 +0300  46) 
41c271da (kx 2025-01-05 15:42:39 +0300  47)   {
41c271da (kx 2025-01-05 15:42:39 +0300  48)     mpu_int16_t    a, b;
41c271da (kx 2025-01-05 15:42:39 +0300  49)     int            nb = NB_I16;
41c271da (kx 2025-01-05 15:42:39 +0300  50)     __mpu_char8_t  s[32];
41c271da (kx 2025-01-05 15:42:39 +0300  51) 
41c271da (kx 2025-01-05 15:42:39 +0300  52)     iatoui( a, "0b11", nb ); /* evaluate the A variable */
41c271da (kx 2025-01-05 15:42:39 +0300  53)     iatoi( b,  "-3", nb );   /* evaluate the B variable */
41c271da (kx 2025-01-05 15:42:39 +0300  54) 
41c271da (kx 2025-01-05 15:42:39 +0300  55)     iitoa( s, a, RADIX_DEC, LOWERCASE, nb ); /* convert A value to ASCII string S */
41c271da (kx 2025-01-05 15:42:39 +0300  56)     printf( "a = %s;\\n", s ); /* a = 3; */
41c271da (kx 2025-01-05 15:42:39 +0300  57) 
41c271da (kx 2025-01-05 15:42:39 +0300  58)     iitoa( s, b, RADIX_BIN, LOWERCASE, nb ); /* convert B value to ASCII string S */
41c271da (kx 2025-01-05 15:42:39 +0300  59)     printf( "b = %s;\\n", s ); /* b = 0b1111111111111101; */
41c271da (kx 2025-01-05 15:42:39 +0300  60)   }
41c271da (kx 2025-01-05 15:42:39 +0300  61) 
41c271da (kx 2025-01-05 15:42:39 +0300  62)   __mpu_free_context();
41c271da (kx 2025-01-05 15:42:39 +0300  63) 
41c271da (kx 2025-01-05 15:42:39 +0300  64)   return( rc );
41c271da (kx 2025-01-05 15:42:39 +0300  65) }
41c271da (kx 2025-01-05 15:42:39 +0300  66) .fi
41c271da (kx 2025-01-05 15:42:39 +0300  67) .SH SEE ALSO
41c271da (kx 2025-01-05 15:42:39 +0300  68) .BR iadd(3),
41c271da (kx 2025-01-05 15:42:39 +0300  69) .BR isub(3),
41c271da (kx 2025-01-05 15:42:39 +0300  70) .BR iadc(3),
41c271da (kx 2025-01-05 15:42:39 +0300  71) .BR isbb(3),
41c271da (kx 2025-01-05 15:42:39 +0300  72) .BR ishl(3),
41c271da (kx 2025-01-05 15:42:39 +0300  73) .BR ishr(3),
41c271da (kx 2025-01-05 15:42:39 +0300  74) .BR isal(3),
41c271da (kx 2025-01-05 15:42:39 +0300  75) .BR isar(3),
41c271da (kx 2025-01-05 15:42:39 +0300  76) .BR irol(3),
41c271da (kx 2025-01-05 15:42:39 +0300  77) .BR iror(3),
41c271da (kx 2025-01-05 15:42:39 +0300  78) .BR ircl(3),
41c271da (kx 2025-01-05 15:42:39 +0300  79) .BR ircr(3),
41c271da (kx 2025-01-05 15:42:39 +0300  80) .BR ishln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  81) .BR ishrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  82) .BR isaln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  83) .BR isarn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  84) .BR iroln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  85) .BR irorn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  86) .BR ircln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  87) .BR ircrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  88) .BR ineg(3),
41c271da (kx 2025-01-05 15:42:39 +0300  89) .BR inot(3),
41c271da (kx 2025-01-05 15:42:39 +0300  90) .BR iand(3),
41c271da (kx 2025-01-05 15:42:39 +0300  91) .BR itest(3),
41c271da (kx 2025-01-05 15:42:39 +0300  92) .BR icmp(3),
41c271da (kx 2025-01-05 15:42:39 +0300  93) .BR ior(3),
41c271da (kx 2025-01-05 15:42:39 +0300  94) .BR ixor(3),
41c271da (kx 2025-01-05 15:42:39 +0300  95) .BR iinc(3),
41c271da (kx 2025-01-05 15:42:39 +0300  96) .BR idec(3),
41c271da (kx 2025-01-05 15:42:39 +0300  97) .BR ixchg(3),
41c271da (kx 2025-01-05 15:42:39 +0300  98) .BR icpy(3),
41c271da (kx 2025-01-05 15:42:39 +0300  99) .BR icvt(3),
41c271da (kx 2025-01-05 15:42:39 +0300 100) .BR imul(3),
41c271da (kx 2025-01-05 15:42:39 +0300 101) .BR ismul(3),
41c271da (kx 2025-01-05 15:42:39 +0300 102) .BR idiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300 103) .BR isdiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300 104) .BR iitoa(3),
41c271da (kx 2025-01-05 15:42:39 +0300 105) .BR iuitoa(3).