-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.h
71 lines (56 loc) · 1.47 KB
/
base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define BASE 10
/*
* Colours
*/
#define GRY "\x1B[1;30m"
#define RED "\x1B[1;31m"
#define GRN "\x1B[1;32m"
#define YLW "\x1B[1;33m"
#define BLU "\x1B[1;34m"
#define MGT "\x1B[0;35m"
#define CYN "\x1B[0;36m"
#define WHT "\x1B[1;37m"
#define NRM "\x1B[0m"
/*
* Report program arguments in colour
*/
#define PRINT_ARGS(argc, argv) do { \
fprintf(stderr, "%sargc %s%2d%s, argv [ %s", GRY, NRM, (argc), GRY, CYN); \
for (int i = 0; i < (argc); i++) fprintf(stderr, "%s ", (argv)[i]); \
fprintf(stderr, "%s]%s\n", GRY, NRM); \
} while (0)
/*
* Unavoidable "assert", in colour
*/
#define CHECK(x) do { \
if(!(x)) { \
fprintf(stderr, "%sFAIL %s%s %s%s%s %s%s:%s%i\n", RED, WHT, #x, GRY, __func__, NRM, __FILE__, GRY, NRM, __LINE__); \
exit(1); \
} \
} while (0)
/*
* "Low-noise" squaring for arguments with no side-effects
*/
#define SQR(x) ((x) * (x))
/*
* Floating point internal format
*/
typedef long double real;
/*
* Point is an array of dimension n together with a cost function value
*/
typedef struct Point {
real *x;
real f;
} point;
void randomize (void);
real rand_range (real lower, real upper);
point *get_point (int n);
void set_random_coordinates (point *p, int n, real lower, real upper);
void copy_point (int n, const point *src, point *dst);
real distance (int, const point *, const point *);
void print_result (int n, const point *p, int places, int fmt);