Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cubit"
version = "1.3.0"
cairo-version = ">=2.4.0"
cairo-version = ">=2.6.4"
edition = "2023_10"
description = "Math library in Cairo using a 64.64 fixed point representation"
homepage = "https://github.com/influenceth/cubit"
Expand Down
2 changes: 1 addition & 1 deletion src/f128/math/comp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn min(a: Fixed, b: Fixed) -> Fixed {
}
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/math/hyp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn atanh(a: Fixed) -> Fixed {
return ln_arg.ln() / FixedTrait::new_unscaled(2_u128, false);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/math/ops.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn _split_unsigned(a: Fixed) -> (u128, u128) {
return integer::u128_safe_divmod(a.mag, integer::u128_as_non_zero(ONE_u128));
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/math/trig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn _sin_loop(a: Fixed, i: u128, acc: Fixed) -> Fixed {
return _sin_loop(a, i - 1, new_acc);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/procgen/rand.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn _fixed_normal_between_loop(
return _fixed_normal_between_loop(seed, low, high, acc + sample, iter - 1);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/procgen/simplex3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn noise_octaves(v: Vec3, mut octaves: u128, persistence: Fixed) -> Fixed {

// TODO: get noise at percentile

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
18 changes: 13 additions & 5 deletions src/f128/types/fixed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ impl FixedImpl of FixedTrait {
}

fn new_unscaled(mag: u128, sign: bool) -> Fixed {
return FixedTrait::new(mag * ONE_u128, sign);
return Self::new(mag * ONE_u128, sign);
}

fn from_felt(val: felt252) -> Fixed {
let mag = core::integer::u128_try_from_felt252(utils::felt_abs(val)).unwrap();
return FixedTrait::new(mag, utils::felt_sign(val));
return Self::new(mag, utils::felt_sign(val));
}

fn from_unscaled_felt(val: felt252) -> Fixed {
return FixedTrait::from_felt(val * ONE);
return Self::from_felt(val * ONE);
}

fn abs(self: Fixed) -> Fixed {
Expand Down Expand Up @@ -424,51 +424,59 @@ impl FixedPartialEq of PartialEq<Fixed> {
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedAdd of Add<Fixed> {
fn add(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::add(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedAddEq of AddEq<Fixed> {
#[inline(always)]
fn add_eq(ref self: Fixed, other: Fixed) {
self = Add::add(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedSub of Sub<Fixed> {
fn sub(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::sub(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedSubEq of SubEq<Fixed> {
#[inline(always)]
fn sub_eq(ref self: Fixed, other: Fixed) {
self = Sub::sub(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedMul of Mul<Fixed> {
fn mul(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::mul(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedMulEq of MulEq<Fixed> {
#[inline(always)]
fn mul_eq(ref self: Fixed, other: Fixed) {
self = Mul::mul(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedDiv of Div<Fixed> {
fn div(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::div(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedDivEq of DivEq<Fixed> {
#[inline(always)]
fn div_eq(ref self: Fixed, other: Fixed) {
Expand Down Expand Up @@ -551,7 +559,7 @@ impl FixedOne of core::num::traits::One<Fixed> {
}
#[inline(always)]
fn is_one(self: @Fixed) -> bool {
*self == FixedOne::one()
*self == Self::one()
}
#[inline(always)]
fn is_non_one(self: @Fixed) -> bool {
Expand All @@ -560,7 +568,7 @@ impl FixedOne of core::num::traits::One<Fixed> {
}


// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/types/vec2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn sub(a: Vec2, b: Vec2) -> Vec2 {
return Vec2 { x: a.x - b.x, y: a.y - b.y };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/types/vec3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn sub(a: Vec3, b: Vec3) -> Vec3 {
return Vec3 { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f128/types/vec4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn sub(a: Vec4, b: Vec4) -> Vec4 {
return Vec4 { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z, w: a.w - b.w };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/math/comp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn min(a: Fixed, b: Fixed) -> Fixed {
}
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/math/hyp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn atanh(a: Fixed) -> Fixed {
return ln_arg.ln() / FixedTrait::new(TWO, false);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/math/ops.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn sub(a: Fixed, b: Fixed) -> Fixed {
return add(a, -b);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/math/trig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn _sin_loop(a: Fixed, i: u64, acc: Fixed) -> Fixed {
return _sin_loop(a, i - 1, new_acc);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/procgen/rand.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn _fixed_normal_between_loop(
return _fixed_normal_between_loop(seed, low, high, acc + sample, iter - 1);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/procgen/simplex3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn noise_octaves(v: Vec3, mut octaves: u64, persistence: Fixed) -> Fixed {

// TODO: get noise at percentile

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
14 changes: 11 additions & 3 deletions src/f64/types/fixed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl FixedImpl of FixedTrait {

fn from_felt(val: felt252) -> Fixed {
let mag = core::integer::u64_try_from_felt252(utils::felt_abs(val)).unwrap();
return FixedTrait::new(mag, utils::felt_sign(val));
return Self::new(mag, utils::felt_sign(val));
}

fn from_unscaled_felt(val: felt252) -> Fixed {
return FixedTrait::from_felt(val * ONE.into());
return Self::from_felt(val * ONE.into());
}

fn abs(self: Fixed) -> Fixed {
Expand Down Expand Up @@ -423,51 +423,59 @@ impl FixedPartialEq of PartialEq<Fixed> {
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedAdd of Add<Fixed> {
fn add(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::add(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedAddEq of AddEq<Fixed> {
#[inline(always)]
fn add_eq(ref self: Fixed, other: Fixed) {
self = Add::add(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedSub of Sub<Fixed> {
fn sub(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::sub(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedSubEq of SubEq<Fixed> {
#[inline(always)]
fn sub_eq(ref self: Fixed, other: Fixed) {
self = Sub::sub(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedMul of Mul<Fixed> {
fn mul(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::mul(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedMulEq of MulEq<Fixed> {
#[inline(always)]
fn mul_eq(ref self: Fixed, other: Fixed) {
self = Mul::mul(self, other);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedDiv of Div<Fixed> {
fn div(lhs: Fixed, rhs: Fixed) -> Fixed {
return ops::div(lhs, rhs);
}
}

#[feature("deprecated-op-assign-traits")]
impl FixedDivEq of DivEq<Fixed> {
#[inline(always)]
fn div_eq(ref self: Fixed, other: Fixed) {
Expand Down Expand Up @@ -548,7 +556,7 @@ impl FixedOne of core::num::traits::One<Fixed> {
}
#[inline(always)]
fn is_one(self: @Fixed) -> bool {
*self == FixedOne::one()
*self == Self::one()
}
#[inline(always)]
fn is_non_one(self: @Fixed) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/types/vec2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn sub(a: Vec2, b: Vec2) -> Vec2 {
return Vec2 { x: a.x - b.x, y: a.y - b.y };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/types/vec3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn sub(a: Vec3, b: Vec3) -> Vec3 {
return Vec3 { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/f64/types/vec4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn sub(a: Vec4, b: Vec4) -> Vec4 {
return Vec4 { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z, w: a.w - b.w };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/math/trig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn _sin_loop(a: Fixed, i: u128, acc: Fixed) -> Fixed {
return _sin_loop(a, i - 1, new_acc);
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/types/vec2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn sub(a: Vec2, b: Vec2) -> Vec2 {
return Vec2 { x: a.x - b.x, y: a.y - b.y };
}

// Tests --------------------------------------------------------------------------------------------------------------
// Tests

#[cfg(test)]
mod tests {
Expand Down