diff --git a/bmm-dem.c b/bmm-dem.c index 8d9a3b6..c4ddcad 100644 --- a/bmm-dem.c +++ b/bmm-dem.c @@ -11,6 +11,7 @@ #include "dem.h" #include "ext.h" +#include "fp.h" #include "opt.h" #include "str.h" #include "tle.h" @@ -48,7 +49,7 @@ static bool f(char const* const key, char const* const value, istage = bmm_dem_script_addstage(opts); opts->script.mode[istage] = BMM_DEM_MODE_CREATE; - opts->script.params[istage].create.eta = 1.0; + opts->script.params[istage].create.eta = M_2PI / (4.0 * sqrt(3.0)); istage = bmm_dem_script_addstage(opts); opts->script.mode[istage] = BMM_DEM_MODE_SEDIMENT; diff --git a/cpp.h b/cpp.h index e4d742c..9016831 100644 --- a/cpp.h +++ b/cpp.h @@ -90,6 +90,82 @@ /// See `BMM_POW_0`. #define BMM_POW(x, n) BMM_POW_(x, n) +// These were generated with `./fact 64`. +#define BMM_FACT_0() (1) +#define BMM_FACT_1() (1 * 1) +#define BMM_FACT_2() (1 * 1 * 2) +#define BMM_FACT_3() (1 * 1 * 2 * 3) +#define BMM_FACT_4() (1 * 1 * 2 * 3 * 4) +#define BMM_FACT_5() (1 * 1 * 2 * 3 * 4 * 5) +#define BMM_FACT_6() (1 * 1 * 2 * 3 * 4 * 5 * 6) +#define BMM_FACT_7() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7) +#define BMM_FACT_8() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8) +#define BMM_FACT_9() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9) +#define BMM_FACT_10() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10) +#define BMM_FACT_11() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11) +#define BMM_FACT_12() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12) +#define BMM_FACT_13() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13) +#define BMM_FACT_14() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14) +#define BMM_FACT_15() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15) +#define BMM_FACT_16() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16) +#define BMM_FACT_17() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17) +#define BMM_FACT_18() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18) +#define BMM_FACT_19() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19) +#define BMM_FACT_20() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20) +#define BMM_FACT_21() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21) +#define BMM_FACT_22() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22) +#define BMM_FACT_23() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23) +#define BMM_FACT_24() (1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23 * 24) +#define BMM_FACT_25() (1 * 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) +#define BMM_FACT_26() (1 * 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) +#define BMM_FACT_27() (1 * 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) +#define BMM_FACT_28() (1 * 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) +#define BMM_FACT_29() (1 * 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) +#define BMM_FACT_30() (1 * 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) +#define BMM_FACT_31() (1 * 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) +#define BMM_FACT_32() (1 * 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) +#define BMM_FACT_33() (1 * 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) +#define BMM_FACT_34() (1 * 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) +#define BMM_FACT_35() (1 * 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) +#define BMM_FACT_36() (1 * 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) +#define BMM_FACT_37() (1 * 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) +#define BMM_FACT_38() (1 * 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) +#define BMM_FACT_39() (1 * 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) +#define BMM_FACT_40() (1 * 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) +#define BMM_FACT_41() (1 * 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) +#define BMM_FACT_42() (1 * 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) +#define BMM_FACT_43() (1 * 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) +#define BMM_FACT_44() (1 * 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) +#define BMM_FACT_45() (1 * 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) +#define BMM_FACT_46() (1 * 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) +#define BMM_FACT_47() (1 * 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) +#define BMM_FACT_48() (1 * 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) +#define BMM_FACT_49() (1 * 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) +#define BMM_FACT_50() (1 * 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) +#define BMM_FACT_51() (1 * 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) +#define BMM_FACT_52() (1 * 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) +#define BMM_FACT_53() (1 * 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) +#define BMM_FACT_54() (1 * 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) +#define BMM_FACT_55() (1 * 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) +#define BMM_FACT_56() (1 * 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) +#define BMM_FACT_57() (1 * 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) +#define BMM_FACT_58() (1 * 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) +#define BMM_FACT_59() (1 * 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) +#define BMM_FACT_60() (1 * 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) +#define BMM_FACT_61() (1 * 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) +#define BMM_FACT_62() (1 * 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) +#define BMM_FACT_63() (1 * 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) +#define BMM_FACT_64() (1 * 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) + +/// The preprocessor directive `BMM_FACT_n(n)` +/// expands to the factorial of `n`. +#define BMM_FACT_(n) BMM_FACT_##n() + +/// The preprocessor directive `BMM_FACT(x, n)` +/// expands to the factorial of `n`. +/// See `BMM_FACT_0`. +#define BMM_FACT(n) BMM_FACT_(n) + /// The preprocessor directive `BMM_MASKALL(x, m)` /// checks whether all bits in `x` match the bit mask `m`. #define BMM_MASKALL(x, m) ((~(x) & (m)) == 0) diff --git a/fact.c b/fact.c new file mode 100644 index 0000000..0d22e4d --- /dev/null +++ b/fact.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +static bool terms(size_t const n) { + if (printf("(1") < 0) + return false; + + for (size_t i = 0; i < n; ++i) + if (printf(" * %zu", i + 1) < 0) + return false; + + if (printf(")") < 0) + return false; + + return true; +} + +static bool dirs(size_t const n) { + for (size_t i = 0; i <= n; ++i) + if (printf("#define BMM_FACT_%zu() ", i) < 0 || + !terms(i) || + printf("\n") < 0) + return false; + + return true; +} + +int main(int const argc, char** const argv) { + if (argc != 2) + return EXIT_FAILURE; + + unsigned long int n = strtoul(argv[1], NULL, 10); + if (n == ULONG_MAX) + return EXIT_FAILURE; + + if (!dirs((size_t) n)) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/fp.h b/fp.h index 2b632e2..9760c7c 100644 --- a/fp.h +++ b/fp.h @@ -194,7 +194,7 @@ inline double bmm_fp_uwrap(double const x, double const b) { /// The call `bmm_fp_fact(n)` /// returns the factorial of `n`. -__attribute__ ((__const__, __pure__)) +__attribute__ ((__const__, __deprecated__, __pure__)) inline double bmm_fp_fact(size_t const n) { double x = 1.0; diff --git a/geom.h b/geom.h index 1d1e453..489b7b7 100644 --- a/geom.h +++ b/geom.h @@ -5,6 +5,7 @@ #include #include +#include "cpp.h" #include "ext.h" #include "fp.h" @@ -15,12 +16,12 @@ __attribute__ ((__const__, __pure__)) inline double bmm_geom_ballvol(double const r, size_t d) { // return d == 0 ? 1.0 : d == 1 ? 2.0 * r : - // (M_2PI * bmm_fp_sq(r) / (double) d) * bmm_geom_ballvol(r, d - 2); + // (M_2PI * BMM_POW(r, 2) / (double) d) * bmm_geom_ballvol(r, d - 2); double v = d % 2 == 0 ? 1.0 : 2.0 * r; while (d > 1) { - v *= M_2PI * bmm_fp_sq(r) / (double) d; + v *= M_2PI * BMM_POW(r, 2) / (double) d; d -= 2; } @@ -35,13 +36,13 @@ inline double bmm_geom_ballvol(double const r, size_t d) { __attribute__ ((__const__, __pure__)) inline double bmm_geom_ballsurf(double const r, size_t d) { // return d == 0 ? 0.0 : d == 1 ? 2.0 : d == 2 ? M_2PI * r : - // (M_2PI * bmm_fp_sq(r) / (double) (d - 2)) * bmm_geom_ballsurf(r, d - 2); + // (M_2PI * BMM_POW(r, 2) / (double) (d - 2)) * bmm_geom_ballsurf(r, d - 2); double a = d == 0 ? 0.0 : d % 2 == 1 ? 2.0 : M_2PI * r; while (d > 2) { d -= 2; - a *= M_2PI * bmm_fp_sq(r) / (double) d; + a *= M_2PI * BMM_POW(r, 2) / (double) d; } return a; @@ -71,7 +72,7 @@ inline double bmm_geom_ballrmoi(size_t const d) { __attribute__ ((__const__, __pure__)) inline double bmm_geom_ballmoi(double const m, double const r, size_t const d) { - return bmm_geom_ballrmoi(d) * m * bmm_fp_sq(r); + return bmm_geom_ballrmoi(d) * m * BMM_POW(r, 2); } /// The call `bmm_geom_ballprmoi(d)` @@ -97,7 +98,48 @@ inline double bmm_geom_ballprmoi(size_t const d) { __attribute__ ((__const__, __pure__)) inline double bmm_geom_ballpmoi(double const m, double const r, size_t const d) { - return bmm_geom_ballprmoi(d) * m * bmm_fp_sq(r); + return bmm_geom_ballprmoi(d) * m * BMM_POW(r, 2); +} + +/// The call `bmm_geom_ballmpd(d)` +/// returns the maximal packing density of balls in `d` dimensions. +/// The density is only known for +/// +/// * 1, +/// * 2, +/// * 3, +/// * 8 and +/// * 24 +/// +/// dimensions; densities for all other dimensions are approximations. +__attribute__ ((__const__, __pure__)) +inline double bmm_geom_ballmpd(size_t const d) { + static double const delta[] = { + NAN, 0.5, 0.28868, 0.17678, 0.125, 0.08839, + 0.07217, 0.0625, 0.0625, 0.04419, 0.03906, 0.03516, + 0.03704, 0.03516, 0.03608, 0.04419, 0.0625, 0.0625, + 0.07508, 0.08839, 0.13154, 0.17678, 0.33254, 0.5, + 1.0, 0.70711, 0.57735, 0.70711, 1.0, 0.70711, + 1.0, 1.2095, 2.5658, 2.2220, 2.2220, 2.8284, 4.4394 + }; + + // TODO This. + // return (pow(M_PI, (double) d / 2.0) / gsl_sf_gamma((double) d / 2.0 + 1)) * delta[d]; + + switch (d) { + case 1: + return 1.0; + case 2: + return M_2PI / (4.0 * sqrt(2.0)); + case 3: + return M_2PI / (6.0 * sqrt(2.0)); + case 8: + return BMM_POW(M_2PI / 4.0, 4) / BMM_FACT(4); + case 24: + return BMM_POW(M_2PI / 2.0, 12) / BMM_FACT(12); + } + + return NAN; } #endif diff --git a/pow.c b/pow.c index 2108f91..25bb7a8 100644 --- a/pow.c +++ b/pow.c @@ -9,7 +9,7 @@ static bool terms(size_t const n) { return false; for (size_t i = 0; i < n; ++i) - if (printf(" * (x)", i) < 0) + if (printf(" * (x)") < 0) return false; if (printf(")") < 0) diff --git a/size.h b/size.h index af649e3..acbf663 100644 --- a/size.h +++ b/size.h @@ -260,7 +260,7 @@ inline size_t bmm_size_dec(size_t const n, size_t const a, size_t const b) { /// The call `bmm_size_fact(n)` /// returns the factorial of `n`. -__attribute__ ((__const__, __pure__)) +__attribute__ ((__const__, __deprecated__, __pure__)) inline size_t bmm_size_fact(size_t const n) { size_t k = 1;