Skip to content
Merged
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
4 changes: 2 additions & 2 deletions mops.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/NatLabs/ByteUtils"

[dependencies]
base = "0.14.11"
xtended-numbers = "0.4.0"
xtended-numbers = "2.0.0"

[dev-dependencies]
test = "2.1.1"
Expand All @@ -18,5 +18,5 @@ augmented-btrees = "0.6.0"
itertools = "0.2.2"

[toolchain]
moc = "0.14.9"
moc = "0.14.13"
wasmtime = "28.0.1"
22 changes: 11 additions & 11 deletions src/lib.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Int64 "mo:base/Int64";
import Int "mo:base/Int";
import Nat "mo:base/Nat";
import Debug "mo:base/Debug";
import BInterface "mo:buffer";

import FloatX "mo:xtended-numbers/FloatX";

Expand Down Expand Up @@ -113,7 +114,7 @@ module ByteUtils {
};

public func toFloat(bytes : Bytes) : Float {
let ?fx = FloatX.decode(bytes, #f64, #lsb) else Debug.trap("ByteUtils: failed to decode Float");
let ?fx = FloatX.fromBytes(bytes, #f64, #lsb) else Debug.trap("ByteUtils: failed to decode Float");
FloatX.toFloat(fx);
};

Expand Down Expand Up @@ -159,7 +160,7 @@ module ByteUtils {
let fx = FloatX.fromFloat(f, #f64);
let buffer = B.Buffer<Nat8>(8);

FloatX.encode(buffer, fx, #lsb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(buffer), fx, #lsb);
B.toArray(buffer);
};

Expand Down Expand Up @@ -218,7 +219,7 @@ module ByteUtils {
};

public func toFloat(bytes : Bytes) : Float {
let ?fx = FloatX.decode(bytes, #f64, #msb) else Debug.trap("ByteUtils: failed to decode Float");
let ?fx = FloatX.fromBytes(bytes, #f64, #msb) else Debug.trap("ByteUtils: failed to decode Float");
FloatX.toFloat(fx);
};

Expand Down Expand Up @@ -264,7 +265,7 @@ module ByteUtils {
let fx = FloatX.fromFloat(f, #f64);
let buffer = B.Buffer<Nat8>(8);

FloatX.encode(buffer, fx, #msb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(buffer), fx, #msb);
B.toArray(buffer);
};

Expand Down Expand Up @@ -327,7 +328,7 @@ module ByteUtils {
// IEEE-754 sortable encoding
let fx = FloatX.fromFloat(f, #f64);
let buffer = B.Buffer<Nat8>(8);
FloatX.encode(buffer, fx, #msb); // Use big-endian
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(buffer), fx, #msb); // Use big-endian

let bytes = B.toArray(buffer);

Expand Down Expand Up @@ -446,7 +447,7 @@ module ByteUtils {
);
};

let ?fx = FloatX.decode(decodedBytes.vals(), #f64, #msb) else Debug.trap("ByteUtils: failed to decode Float");
let ?fx = FloatX.fromBytes(decodedBytes.vals(), #f64, #msb) else Debug.trap("ByteUtils: failed to decode Float");
FloatX.toFloat(fx);
};
};
Expand Down Expand Up @@ -573,7 +574,7 @@ module ByteUtils {

public func addFloat(buffer : B.Buffer<Nat8>, f : Float) {
let fx = FloatX.fromFloat(f, #f64);
FloatX.encode(buffer, fx, #lsb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(buffer), fx, #lsb);
};

// Add new write methods (write at specific offset)
Expand Down Expand Up @@ -629,7 +630,7 @@ module ByteUtils {
public func writeFloat(buffer : BufferLike<Nat8>, offset : Nat, f : Float) {
let fx = FloatX.fromFloat(f, #f64);
let tempBuffer = B.Buffer<Nat8>(8);
FloatX.encode(tempBuffer, fx, #lsb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(tempBuffer), fx, #lsb);

// Copy from temp buffer to target buffer at offset
for (i in Iter.range(0, 7)) {
Expand Down Expand Up @@ -743,7 +744,7 @@ module ByteUtils {

public func addFloat(buffer : B.Buffer<Nat8>, f : Float) {
let fx = FloatX.fromFloat(f, #f64);
FloatX.encode(buffer, fx, #msb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(buffer), fx, #msb);
};

// Add new write methods (write at specific offset)
Expand Down Expand Up @@ -799,7 +800,7 @@ module ByteUtils {
public func writeFloat(buffer : B.Buffer<Nat8>, offset : Nat, f : Float) {
let fx = FloatX.fromFloat(f, #f64);
let tempBuffer = B.Buffer<Nat8>(8);
FloatX.encode(tempBuffer, fx, #msb);
FloatX.toBytesBuffer(BInterface.fromDeprecatedBuffer(tempBuffer), fx, #msb);

// Copy from temp buffer to target buffer at offset
for (i in Iter.range(0, 7)) {
Expand Down Expand Up @@ -1346,5 +1347,4 @@ module ByteUtils {
};

};

};
Loading