Add Num.mix()
This commit is contained in:
parent
d2348f0894
commit
5fd85d7e0b
@ -64,6 +64,10 @@ public double Num$random(void) {
|
|||||||
return drand48();
|
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) {
|
public double Num$from_text(CORD text, CORD *the_rest) {
|
||||||
const char *str = CORD_to_const_char_star(text);
|
const char *str = CORD_to_const_char_star(text);
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
@ -142,6 +146,10 @@ public float Num32$random(void) {
|
|||||||
return (float)drand48();
|
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) {
|
public float Num32$from_text(CORD text, CORD *the_rest) {
|
||||||
const char *str = CORD_to_const_char_star(text);
|
const char *str = CORD_to_const_char_star(text);
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
|
@ -24,6 +24,7 @@ bool Num$finite(double n);
|
|||||||
bool Num$isnan(double n);
|
bool Num$isnan(double n);
|
||||||
double Num$nan(CORD tag);
|
double Num$nan(CORD tag);
|
||||||
double Num$random(void);
|
double Num$random(void);
|
||||||
|
double Num$mix(double amount, double x, double y);
|
||||||
double Num$from_text(CORD text, CORD *the_rest);
|
double Num$from_text(CORD text, CORD *the_rest);
|
||||||
extern const TypeInfo $Num;
|
extern const TypeInfo $Num;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ bool Num32$isinf(float n);
|
|||||||
bool Num32$finite(float n);
|
bool Num32$finite(float n);
|
||||||
bool Num32$isnan(float n);
|
bool Num32$isnan(float n);
|
||||||
float Num32$random(void);
|
float Num32$random(void);
|
||||||
|
float Num32$mix(float amount, float x, float y);
|
||||||
float Num32$from_text(CORD text, CORD *the_rest);
|
float Num32$from_text(CORD text, CORD *the_rest);
|
||||||
float Num32$nan(CORD tag);
|
float Num32$nan(CORD tag);
|
||||||
extern const TypeInfo $Num32;
|
extern const TypeInfo $Num32;
|
||||||
|
@ -114,6 +114,7 @@ env_t *new_compilation_unit(void)
|
|||||||
{"INF", "INFINITY", "Num"},
|
{"INF", "INFINITY", "Num"},
|
||||||
{"TAU", "(2.*M_PI)", "Num"},
|
{"TAU", "(2.*M_PI)", "Num"},
|
||||||
{"random", "Num$random", "func()->Num"},
|
{"random", "Num$random", "func()->Num"},
|
||||||
|
{"mix", "Num$mix", "func(amount:Num, x:Num, y:Num)->Num"},
|
||||||
{"from_text", "Num$from_text", "func(text:Text, the_rest=!Text)->Num"},
|
{"from_text", "Num$from_text", "func(text:Text, the_rest=!Text)->Num"},
|
||||||
{"abs", "fabs", "func(n:Num)->Num"},
|
{"abs", "fabs", "func(n:Num)->Num"},
|
||||||
F(acos), F(acosh), F(asin), F(asinh), F(atan), F(atanh), F(cbrt), F(ceil), F(cos), F(cosh), F(erf), F(erfc),
|
F(acos), F(acosh), F(asin), F(asinh), F(atan), F(atanh), F(cbrt), F(ceil), F(cos), F(cosh), F(erf), F(erfc),
|
||||||
@ -141,6 +142,7 @@ env_t *new_compilation_unit(void)
|
|||||||
{"INF", "(Num32_t)(INFINITY)", "Num32"},
|
{"INF", "(Num32_t)(INFINITY)", "Num32"},
|
||||||
{"TAU", "(Num32_t)(2.f*M_PI)", "Num32"},
|
{"TAU", "(Num32_t)(2.f*M_PI)", "Num32"},
|
||||||
{"random", "Num32$random", "func()->Num32"},
|
{"random", "Num32$random", "func()->Num32"},
|
||||||
|
{"mix", "Num32$mix", "func(amount:Num32, x:Num32, y:Num32)->Num32"},
|
||||||
{"from_text", "Num32$from_text", "func(text:Text, the_rest=!Text)->Num32"},
|
{"from_text", "Num32$from_text", "func(text:Text, the_rest=!Text)->Num32"},
|
||||||
{"abs", "fabsf", "func(n:Num32)->Num32"},
|
{"abs", "fabsf", "func(n:Num32)->Num32"},
|
||||||
F(acos), F(acosh), F(asin), F(asinh), F(atan), F(atanh), F(cbrt), F(ceil), F(cos), F(cosh), F(erf), F(erfc),
|
F(acos), F(acosh), F(asin), F(asinh), F(atan), F(atanh), F(cbrt), F(ceil), F(cos), F(cosh), F(erf), F(erfc),
|
||||||
|
@ -48,3 +48,8 @@ func main()
|
|||||||
|
|
||||||
>> Num32.sqrt(16f32)
|
>> Num32.sqrt(16f32)
|
||||||
= 4_f32
|
= 4_f32
|
||||||
|
|
||||||
|
>> 0.25:mix(10, 20)
|
||||||
|
= 12.5
|
||||||
|
>> 2.0:mix(10, 20)
|
||||||
|
= 30
|
||||||
|
Loading…
Reference in New Issue
Block a user