Skip to content

Commit

Permalink
fix(katana): Fixed for calculation with Double?
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Aug 16, 2022
1 parent 6a6ed9b commit 6388ca7
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions packages/katana/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,34 @@ extension NullableNumExtensions on num? {
}
return this! / other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
num? operator %(num? other) {
if (this == null) {
return other;
}
if (other == null) {
return this;
}
return this! % other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
int? operator ~/(num? other) {
if (this == null) {
return other?.toInt();
}
if (other == null) {
return this?.toInt();
}
return this! ~/ other;
}
}

/// Provides general extensions to [int?].
Expand Down Expand Up @@ -1177,6 +1205,90 @@ extension NullableDoubleExtensions on double? {
}
return this != 0.0;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
double? operator +(num? other) {
if (this == null) {
return other?.toDouble();
}
if (other == null) {
return this;
}
return this! + other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
double? operator -(num? other) {
if (this == null) {
return other?.toDouble();
}
if (other == null) {
return this;
}
return this! - other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
double? operator *(num? other) {
if (this == null) {
return other?.toDouble();
}
if (other == null) {
return this;
}
return this! - other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
double? operator /(num? other) {
if (this == null) {
return other?.toDouble();
}
if (other == null) {
return this;
}
return this! / other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
double? operator %(num? other) {
if (this == null) {
return other?.toDouble();
}
if (other == null) {
return this;
}
return this! % other;
}

/// Calculation assuming Null.
///
/// If both are null, null is returned.
/// If either is not null, a non-null value is returned.
int? operator ~/(num? other) {
if (this == null) {
return other?.toInt();
}
if (other == null) {
return this?.toInt();
}
return this! ~/ other;
}
}

/// Provides general extensions to [int].
Expand Down

0 comments on commit 6388ca7

Please sign in to comment.