2024-02-17 16:32:30 -08:00
|
|
|
#pragma once
|
2024-03-18 09:57:49 -07:00
|
|
|
|
|
|
|
// Type infos and methods for Nums (floating point)
|
|
|
|
|
2024-02-17 16:32:30 -08:00
|
|
|
#include <gc/cord.h>
|
2024-02-27 10:39:12 -08:00
|
|
|
#include <math.h>
|
2024-02-17 16:32:30 -08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2024-02-17 20:27:02 -08:00
|
|
|
#define Num_t double
|
2024-03-03 10:37:05 -08:00
|
|
|
#define Num32_t float
|
2024-08-10 13:03:00 -07:00
|
|
|
#define N32(n) ((float)n)
|
|
|
|
#define N64(n) ((double)n)
|
2024-02-17 20:27:02 -08:00
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
Text_t Num$as_text(const double *f, bool colorize, const TypeInfo *type);
|
2024-03-29 09:54:31 -07:00
|
|
|
int32_t Num$compare(const double *x, const double *y, const TypeInfo *type);
|
|
|
|
bool Num$equal(const double *x, const double *y, const TypeInfo *type);
|
|
|
|
bool Num$near(double a, double b, double ratio, double absolute);
|
2024-09-02 15:47:39 -07:00
|
|
|
Text_t Num$format(double f, Int_t precision);
|
|
|
|
Text_t Num$scientific(double f, Int_t precision);
|
2024-03-29 09:54:31 -07:00
|
|
|
double Num$mod(double num, double modulus);
|
|
|
|
bool Num$isinf(double n);
|
|
|
|
bool Num$finite(double n);
|
|
|
|
bool Num$isnan(double n);
|
2024-09-02 15:47:39 -07:00
|
|
|
double Num$nan(Text_t tag);
|
2024-03-29 09:54:31 -07:00
|
|
|
double Num$random(void);
|
2024-04-22 11:49:36 -07:00
|
|
|
double Num$mix(double amount, double x, double y);
|
2024-09-04 13:08:34 -07:00
|
|
|
double Num$from_text(Text_t text, bool *success);
|
2024-08-18 20:20:54 -07:00
|
|
|
static inline double Num$clamped(double x, double low, double high) {
|
|
|
|
return (x <= low) ? low : (x >= high ? high : x);
|
|
|
|
}
|
2024-09-05 12:31:54 -07:00
|
|
|
extern const TypeInfo Num$info;
|
2024-02-17 16:32:30 -08:00
|
|
|
|
2024-09-02 15:47:39 -07:00
|
|
|
Text_t Num32$as_text(const float *f, bool colorize, const TypeInfo *type);
|
2024-03-29 09:54:31 -07:00
|
|
|
int32_t Num32$compare(const float *x, const float *y, const TypeInfo *type);
|
|
|
|
bool Num32$equal(const float *x, const float *y, const TypeInfo *type);
|
|
|
|
bool Num32$near(float a, float b, float ratio, float absolute);
|
2024-09-02 15:47:39 -07:00
|
|
|
Text_t Num32$format(float f, Int_t precision);
|
|
|
|
Text_t Num32$scientific(float f, Int_t precision);
|
2024-03-29 09:54:31 -07:00
|
|
|
float Num32$mod(float num, float modulus);
|
|
|
|
bool Num32$isinf(float n);
|
|
|
|
bool Num32$finite(float n);
|
|
|
|
bool Num32$isnan(float n);
|
|
|
|
float Num32$random(void);
|
2024-04-22 11:49:36 -07:00
|
|
|
float Num32$mix(float amount, float x, float y);
|
2024-09-04 13:08:34 -07:00
|
|
|
float Num32$from_text(Text_t text, bool *success);
|
2024-09-02 15:47:39 -07:00
|
|
|
float Num32$nan(Text_t tag);
|
2024-08-18 20:20:54 -07:00
|
|
|
static inline float Num32$clamped(float x, float low, float high) {
|
|
|
|
return (x <= low) ? low : (x >= high ? high : x);
|
|
|
|
}
|
2024-09-05 12:31:54 -07:00
|
|
|
extern const TypeInfo Num32$info;
|
2024-02-17 16:32:30 -08:00
|
|
|
|
|
|
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|