Skip to content

Commit

Permalink
chore: update jane libs (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: khaira nabila <[email protected]>
  • Loading branch information
khairanabila authored Mar 25, 2024
1 parent 51e6aa0 commit 99e3b0b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
21 changes: 10 additions & 11 deletions lib/array/copy.jn
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@
// copy function item to dest
type[Item_T]
pub copy(&destination, &source []Item_T) {
if source.empty() {
ret
} else if destination.empty() {
if source.empty() || destination.empty() {
ret
}

length:size
if destination.len > source.len {
length = source.len
} else if srouce.len > destination.len {
length = destination.len
match {
case destination.len > source.len:
length = source.len
case source.len > destination.len:
length = destination.len
default:
length = source.len
}

index:size = 0
index: size = 0
iter index < length {
destination[index] = source[index]
index ++
index++
}
}
4 changes: 2 additions & 2 deletions lib/array/make.jn
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type[Item_T]
pub make(const n size) []Item_T {
buffer:[]Item_T
if n == 0 {
buffer
ret buffer
}
//cxx: @buffer._buffer = std::vector<@Item_T>(@n, @Item_T{});
buffer
ret buffer
}
36 changes: 19 additions & 17 deletions lib/math/dim.jn
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ pub dim(const x, const y f64) f64 {
//doc:
// return larger of x or y
pub max(const x, const y f64) f64 {
if isinf(x, 1) || isinf(y, 1) {
ret inf(1)
} else if isnan(x) || isnan(y) {
ret nan()
} else if x == 0 && x == y {
if signbit(x) {
ret y
}
ret x
match {
case isinf(x, 1) || isinf(y, 1):
ret inf(1)
case isnan(x) || isnan(y):
ret nan()
case x == 0 && x == y:
if signbit(x) {
ret y
}
ret x
}
if x > y {
ret x
Expand All @@ -42,18 +43,19 @@ pub max(const x, const y f64) f64 {
//doc:
// return small of x or y
pub min(cosnt x, const y f64) f64 {
if isinf(x, -1) || isinf(y, -1) {
match {
case isinf(x, -1) || isinf(y, -1):
ret inf(-1)
} else if isnan(x) || isnan(y) {
case isnan(x) || isnan(y):
ret nan()
} else if x == 0 && x == y {
case x == 0 && x == y:
if signbit(x) {
ret x
}
ret y
}
if x < y {
ret x
}
ret y
}
if x < y {
ret x
}
ret y
}
10 changes: 5 additions & 5 deletions lib/math/sqrt.jn
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
// return the square root of x reference from
// sun microsystem manual
pub sqrt(const x f64) f64 {
if x == 0 || isnan(x) || isinf(x, 1) {
ret x
} else if x < 0 {
ret nan()
match {
case x == 0 || isnan(x) || isinf(x, 1):
ret x
case x < 0:
ret nan()
}
ix: = f64_bits(x)
// normalize x
exp: = int((ix >> shift) & mask)
if exp == 0 {
iter ix&(1 << shift) == 0 {
Expand Down
13 changes: 11 additions & 2 deletions lib/mem/alloc.jn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
type[Alloc_T]
pub calloc(const n size) *Alloc_T {
if n == 0 {
nil
ret nil
}
//cxx: return (@Alloc_T*)(std::calloc(@n, sizeof(@Alloc_T)));
}
Expand All @@ -24,11 +24,20 @@ pub calloc(const n size) *Alloc_T {
// allocate memory by specified size
pub malloc(const size size) voidptr {
if size == 0 {
nil
ret nil
}
//cxx: return std::malloc(@size);
}

//doc:
// resize allocation based on given size
pub realloc(ptr voidptr, const size size) voidptr {
if !ptr {
ret nil
}
//cxx: return std::realloc(@ptr, @size);
}

//doc:
// return pointer to new allocation of data type.
// if allocation is success, otherwise nil
Expand Down
4 changes: 2 additions & 2 deletions lib/mem/copy.jn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// set n value of pointer segment to specified expression
type[Alloc_T]
pub memset(ptr *Alloc_T, expr Alloc_T, const n size) {
if n == 0 {
if n == 0 || !ptr {
ret
} else if !ptr {
ret
Expand All @@ -29,7 +29,7 @@ pub memset(ptr *Alloc_T, expr Alloc_T, const n size) {
// copy n value from souce allocation to destination allocation
type[Alloc_T]
pub memcopy(dest, src *Alloc_T, const n size) {
if n == 0 {
if n == 0 || !dest || !src {
ret
} else if !dest {
ret
Expand Down

0 comments on commit 99e3b0b

Please sign in to comment.