84 lines
1.3 KiB
C
84 lines
1.3 KiB
C
#include <stdio.h>
|
||
#include <stdint.h>
|
||
#include <stdlib.h>
|
||
|
||
struct my_perfect_float
|
||
{
|
||
unsigned char sign;
|
||
signed char exponent;
|
||
unsigned char dop_var;
|
||
int mantissa;
|
||
};
|
||
|
||
// 1. вернуть объект с некорректными данными в нём
|
||
// 2. dm + error_code
|
||
// 3. dm_e
|
||
// 4. error_code as arg
|
||
// 5. global vars
|
||
|
||
int error_code;
|
||
|
||
const int MANTISSA_SIZE = 24;
|
||
|
||
struct dm_e
|
||
{
|
||
struct dm result;
|
||
int error_code;
|
||
};
|
||
|
||
struct dm
|
||
{
|
||
int32_t div;
|
||
int32_t mod;
|
||
};
|
||
|
||
|
||
int divmod(int32_t x, int32_t y, struct dm* dm)
|
||
{
|
||
int aa = 2; // initialization
|
||
aa = 3; // assignment
|
||
int bb; // non-initialize
|
||
if (y == 0)
|
||
{
|
||
return 1;
|
||
}
|
||
*dm = (struct dm){ .div = x / y, .mod = x % y };
|
||
return 0;
|
||
}
|
||
|
||
// x, y => /, %
|
||
struct dm divmod(int32_t x, int32_t y, int *error_code)
|
||
{
|
||
int aa = 2; // initialization
|
||
aa = 3; // assignment
|
||
int bb; // non-initialize
|
||
if (y == 0)
|
||
{
|
||
*error_code = 1;
|
||
return (struct dm) { .div = 0, .mod = 0 };
|
||
}
|
||
//struct dm dm = { .div = x / y, .mod = x % y };
|
||
//return dm;
|
||
return (struct dm){ .div = x / y, .mod = x % y }; // compound literal
|
||
}
|
||
|
||
int main(int argc, char* argv[])
|
||
{
|
||
if (argc != 4)
|
||
{
|
||
// free resourses
|
||
fprintf(stderr, "Usage: %s A.B <rounding> <number>\n", argv[0]);
|
||
return 1;
|
||
}
|
||
|
||
int32_t a, b;
|
||
|
||
int sz = 5;
|
||
// .... 100 lines
|
||
int64_t c;
|
||
|
||
c = 2;
|
||
|
||
return 0;
|
||
}
|