Skip to content

Commit b167504

Browse files
committed
Added modulo operator to BsonValue
1 parent 2cc00c7 commit b167504

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

LiteDB/Document/BsonValue.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ public static implicit operator BsonValue(DateTime value)
500500
return left.AsDouble / right.AsDouble;
501501
}
502502

503+
// %
504+
public static BsonValue operator %(BsonValue left, BsonValue right)
505+
{
506+
if (!left.IsNumber || !right.IsNumber) return BsonValue.Null;
507+
if (left.IsInt32 && right.IsInt32) return left.AsInt32 % right.AsInt32;
508+
if (left.IsInt64 && right.IsInt64) return left.AsInt64 % right.AsInt64;
509+
if (left.IsDecimal && right.IsDecimal) return left.AsDecimal % right.AsDecimal;
510+
511+
return left.AsDouble % right.AsDouble;
512+
}
513+
503514
public override string ToString()
504515
{
505516
return JsonSerializer.Serialize(this);

0 commit comments

Comments
 (0)