diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-22 14:49:36 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-22 14:49:36 -0400 |
| commit | 5fd85d7e0bd7bc9c9c42c8b3ecbc35a2d0329e41 (patch) | |
| tree | dc301107fd6b2f9f4d3ee314afaaee6e3aac0402 /builtins | |
| parent | d2348f0894e9ad6a7d3110407ef0fcadf3ff8973 (diff) | |
Add Num.mix()
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/nums.c | 8 | ||||
| -rw-r--r-- | builtins/nums.h | 2 |
2 files changed, 10 insertions, 0 deletions
diff --git a/builtins/nums.c b/builtins/nums.c index 0ad2bdc2..286b8d1d 100644 --- a/builtins/nums.c +++ b/builtins/nums.c @@ -64,6 +64,10 @@ public double Num$random(void) { return drand48(); } +public double Num$mix(double amount, double x, double y) { + return (1.0-amount)*x + amount*y; +} + public double Num$from_text(CORD text, CORD *the_rest) { const char *str = CORD_to_const_char_star(text); char *end = NULL; @@ -142,6 +146,10 @@ public float Num32$random(void) { return (float)drand48(); } +public float Num32$mix(float amount, float x, float y) { + return (1.0-amount)*x + amount*y; +} + public float Num32$from_text(CORD text, CORD *the_rest) { const char *str = CORD_to_const_char_star(text); char *end = NULL; diff --git a/builtins/nums.h b/builtins/nums.h index 3b4386e0..ec1663a2 100644 --- a/builtins/nums.h +++ b/builtins/nums.h @@ -24,6 +24,7 @@ bool Num$finite(double n); bool Num$isnan(double n); double Num$nan(CORD tag); double Num$random(void); +double Num$mix(double amount, double x, double y); double Num$from_text(CORD text, CORD *the_rest); extern const TypeInfo $Num; @@ -38,6 +39,7 @@ bool Num32$isinf(float n); bool Num32$finite(float n); bool Num32$isnan(float n); float Num32$random(void); +float Num32$mix(float amount, float x, float y); float Num32$from_text(CORD text, CORD *the_rest); float Num32$nan(CORD tag); extern const TypeInfo $Num32; |
