mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added tests to sincos. Correctly detect multiple overloads of the same type. Fix regression quaternion overload. Remove "1." style.
This commit is contained in:
@@ -6,7 +6,6 @@ import std::math::complex;
|
||||
import std::math::matrix;
|
||||
import std::math::quaternion;
|
||||
|
||||
// TODO Define these using quad precision.
|
||||
const E = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466;
|
||||
const LOG2E = 1.44269504088896340735992468100189214; // log2(e)
|
||||
const LOG10E = 0.434294481903251827651128918916605082; // log10(e)
|
||||
@@ -60,6 +59,7 @@ const DOUBLE_EPSILON = 2.22044604925031308085e-16;
|
||||
const QUAD_MANT_DIG = 113;
|
||||
|
||||
/*
|
||||
Currently unsupported float128 constants
|
||||
const QUAD_MAX = 1.18973149535723176508575932662800702e+4932;
|
||||
const QUAD_MIN = 3.36210314311209350626267781732175260e-4932;
|
||||
const QUAD_DENORM_MIN = 6.47517511943802511092443895822764655e-4966;
|
||||
@@ -129,7 +129,7 @@ macro is_approx(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
return abs(x-y) <= eps;
|
||||
return abs(x - y) <= eps;
|
||||
}
|
||||
|
||||
<*
|
||||
@@ -140,7 +140,7 @@ macro is_approx_rel(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
return abs(x-y) <= eps * max(abs(x), abs(y));
|
||||
return abs(x - y) <= eps * max(abs(x), abs(y));
|
||||
}
|
||||
|
||||
<*
|
||||
@@ -149,7 +149,7 @@ macro is_approx_rel(x, y, eps)
|
||||
macro sign(x)
|
||||
{
|
||||
var $Type = $typeof(x);
|
||||
$if $Type.kindof == TypeKind.UNSIGNED_INT:
|
||||
$if $Type.kindof == UNSIGNED_INT:
|
||||
return ($Type)(x > 0);
|
||||
$else
|
||||
return ($Type)(x > 0) - ($Type)(x < 0);
|
||||
@@ -177,7 +177,7 @@ macro atan2(x, y)
|
||||
*>
|
||||
macro sincos_ref(x, sinp, cosp)
|
||||
{
|
||||
$if @typeid(*sinp) == float.typeid:
|
||||
$if @typeis(sinp, float*.typeid):
|
||||
return _sincosf(x, sinp, cosp);
|
||||
$else
|
||||
return _sincos(x, sinp, cosp);
|
||||
@@ -192,7 +192,7 @@ macro sincos_ref(x, sinp, cosp)
|
||||
*>
|
||||
macro sincos(x)
|
||||
{
|
||||
$if @typeid(x) == float.typeid:
|
||||
$if @typeis(x, float):
|
||||
float[<2>] v @noinit;
|
||||
_sincosf(x, &v[0], &v[1]);
|
||||
$else
|
||||
|
||||
@@ -19,12 +19,12 @@ macro Complex Complex.add_real(self, Real r) @operator_s(+) => { .v = self.v + (
|
||||
macro Complex Complex.add_each(self, Real b) => { .v = self.v + b };
|
||||
macro Complex Complex.sub(self, Complex b) @operator(-) => { .v = self.v - b.v };
|
||||
macro Complex Complex.sub_real(self, Real r) @operator(-) => { .v = self.v - (Real[<2>]) { r, 0 } };
|
||||
macro Complex Complex.sub_from_real(self, Real r) @operator_r(-) => { .v = (Real[<2>]) { r, 0 } - self.v };
|
||||
macro Complex Complex.sub_real_inverse(self, Real r) @operator_r(-) => { .v = (Real[<2>]) { r, 0 } - self.v };
|
||||
macro Complex Complex.sub_each(self, Real b) => { .v = self.v - b };
|
||||
macro Complex Complex.scale(self, Real r) @operator_s(*) => { .v = self.v * r };
|
||||
macro Complex Complex.mul(self, Complex b)@operator(*) => { self.r * b.r - self.c * b.c, self.r * b.c + b.r * self.c };
|
||||
macro Complex Complex.div_real(self, Real r) @operator(/) => { .v = self.v / r };
|
||||
macro Complex Complex.real_div(Complex c, Real r) @operator_r(/) => ((Complex) { .r = self }).div(c);
|
||||
macro Complex Complex.div_real_inverse(Complex c, Real r) @operator_r(/) => ((Complex) { .r = self }).div(c);
|
||||
macro Complex Complex.div(self, Complex b) @operator(/)
|
||||
{
|
||||
Real div = b.v.dot(b.v);
|
||||
|
||||
@@ -16,7 +16,7 @@ macro Quaternion Quaternion.add_each(self, Real b) => { .v = self.v + b };
|
||||
macro Quaternion Quaternion.sub(self, Quaternion b) @operator(-) => { .v = self.v - b.v };
|
||||
macro Quaternion Quaternion.negate(self) @operator(-) => { .v = -self.v };
|
||||
macro Quaternion Quaternion.sub_each(self, Real b) => { .v = self.v - b };
|
||||
macro Quaternion Quaternion.scale(self, Real s) @operator(*) => { .v = self.v * s };
|
||||
macro Quaternion Quaternion.scale(self, Real s) @operator_s(*) => { .v = self.v * s };
|
||||
macro Quaternion Quaternion.normalize(self) => { .v = self.v.normalize() };
|
||||
macro Real Quaternion.length(self) => self.v.length();
|
||||
macro Quaternion Quaternion.lerp(self, Quaternion q2, Real amount) => { .v = self.v.lerp(q2.v, amount) };
|
||||
@@ -61,7 +61,7 @@ fn Quaternion Quaternion.slerp(self, Quaternion q2, Real amount)
|
||||
return { .v = q1v * ratio_a + q2v * ratio_b };
|
||||
}
|
||||
|
||||
fn Quaternion Quaternion.mul(self, Quaternion b) @operator(+)
|
||||
fn Quaternion Quaternion.mul(self, Quaternion b) @operator(*)
|
||||
{
|
||||
return { self.i * b.l + self.l * b.i + self.j * b.k - self.k * b.j,
|
||||
self.j * b.l + self.l * b.j + self.k * b.i - self.i * b.k,
|
||||
|
||||
Reference in New Issue
Block a user