Skip to content

Commit 46ddff3

Browse files
committed
factored out most makefiles via symlink + include param file
1 parent 9735aa1 commit 46ddff3

24 files changed

Lines changed: 461 additions & 614 deletions

‎c/c.c‎

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,15 @@ int main( int argc, char** argv )
16721672
assert( s.f == 1.0 );
16731673
}
16741674

1675+
//only works for init
1676+
{
1677+
struct S s;
1678+
//s = {
1679+
// .f = 1.0,
1680+
// .i = 1
1681+
//};
1682+
}
1683+
16751684
//pointer to struct
16761685
{
16771686
struct S s;
@@ -2106,7 +2115,6 @@ int main( int argc, char** argv )
21062115
}
21072116
}
21082117

2109-
21102118
/*
21112119
#NULL pointer
21122120
@@ -2640,6 +2648,7 @@ int main( int argc, char** argv )
26402648
puts(">>>\f<<< feed char");
26412649
puts(">>>\v<<< vertical tab");
26422650
puts(">>>\r<<< carriage return");
2651+
puts(">>>\a<<< alert (your terminal may interpret this as a sound beep or not)");
26432652
printf(">>>%c<<< null char\n",'\0');
26442653
puts(">>>\x61<<< a in hexadecimal");
26452654
puts(">>>\xe4\xb8\xad<<< zhong1, chinese for \"middle\" in utf8"); //chinese utf8
@@ -3301,7 +3310,7 @@ int main( int argc, char** argv )
33013310

33023311
//#preprocessor
33033312
{
3304-
//#define
3313+
//##define
33053314
{
33063315
#define A B
33073316
#define B 1
@@ -3311,7 +3320,7 @@ int main( int argc, char** argv )
33113320
assert( A == 1 );
33123321
}
33133322

3314-
//#ifdef
3323+
//##ifdef
33153324
{
33163325
#ifdef COMMANDLINE
33173326
//gcc -DCOMMANDLINE c.c
@@ -3322,6 +3331,26 @@ int main( int argc, char** argv )
33223331
#endif
33233332
}
33243333

3334+
/*
3335+
##if
3336+
3337+
The preprocessor can do certain integer arithmetic operations such as:
3338+
+, -, ==, <.
3339+
*/
3340+
{
3341+
#define INIF 1
3342+
#if INIF + 1 == 2
3343+
#else
3344+
assert(false);
3345+
#endif
3346+
3347+
#if 16 == 0x10
3348+
#else
3349+
assert(false);
3350+
#endif
3351+
}
3352+
3353+
33253354
//#&&
33263355
#define C 1
33273356
#if defined(C) && C > 0
@@ -3330,7 +3359,7 @@ int main( int argc, char** argv )
33303359
#endif
33313360

33323361
/*
3333-
#error
3362+
##error
33343363
33353364
Print an error message to stderr and stop compilation.
33363365
*/
@@ -4312,32 +4341,63 @@ int main( int argc, char** argv )
43124341

43134342
//#math.h
43144343
{
4344+
const double err = 10e-6;
4345+
4346+
//#abs
4347+
{
4348+
//absolute values, integer version:
4349+
4350+
assert( abs(-1.1) == 1 );
4351+
4352+
//absolute values, float version:
4353+
4354+
assert( fabsl(-1.1) == 1.1 );
4355+
}
4356+
43154357
//max and min for floats (C99):
43164358

43174359
assert( fminl( 0.1, 0.2 ) == 0.1 );
43184360
assert( fmaxl( 0.1, 0.2 ) == 0.2 );
43194361

4320-
//exponential:
4362+
//don't forget to use the float versions which starts with f!
43214363

4322-
assert( fabs( exp(1.0) - 2.71 ) < 0.01 );
4364+
//#rounding
4365+
{
4366+
assert( fabs( floor(0.5) - 0.0 ) < err );
4367+
assert( fabs( ceil(0.5) - 1.0 ) < err );
43234368

4324-
//trig:
4369+
//many more: round, rint, lrint, each with a subtle differences between them
4370+
}
43254371

4326-
assert( fabs( cos(0.0) - 1.0 ) < 0.01 );
4372+
//#exp
4373+
{
43274374

4328-
//this is a standard way to get PI. The only problem is the slight calculation overhead.
4375+
//#exponential #exp
43294376

4330-
assert( fabs( acos(-1.0) - 3.14 ) < 0.01 );
4377+
assert( fabs( exp(1.0) - 2.71 ) < 0.01 );
43314378

4332-
//absolute values, integer version:
4379+
//#log #ln
43334380

4334-
assert( abs(-1.1) == 1 );
4381+
assert( fabs( log( exp(1.0) ) - 1.0 ) < err );
43354382

4336-
//absolute values, float version:
4383+
//#pow power
4384+
4385+
assert( fabs( pow(2.0, 3.0) - 8.0 ) < err );
4386+
}
4387+
4388+
//#trig
4389+
{
4390+
assert( fabs( cos(0.0) - 1.0 ) < err );
4391+
4392+
//this is a standard way to get PI.
4393+
//The only problem is the slight calculation overhead.
4394+
4395+
assert( fabs( acos(-1.0) - 3.14 ) < 0.01 );
4396+
}
43374397

4338-
assert( fabsl(-1.1) == 1.1 );
4398+
//#erf: TODO understand
43394399

4340-
//don't forget to use the float version!
4400+
//#gamma: tgamma, lgamma: TODO understand
43414401

43424402
//#random
43434403
{

0 commit comments

Comments
 (0)