Skip to content

Commit 219ea1d

Browse files
committed
Fix int division bug when computing chunks for each dimension
The calls to Math.ceil were effectivly no-ops, as int/int produces an int, which was then passed to the ceil method.
1 parent b42ae0d commit 219ea1d

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private static int getChunkIndex(RandomAccessDirectoryItem item, ZArray zarray)
397397
int[] shape = zarray.getShape();
398398
int[] chunkSize = zarray.getChunks();
399399
for (int i = 0; i < nDims; i++) {
400-
nChunks[i] = (int) Math.ceil(shape[i] / chunkSize[i]);
400+
nChunks[i] = (int) Math.ceil((double) shape[i] / chunkSize[i]);
401401
}
402402
return ZarrUtils.subscriptsToIndex(subs, nChunks);
403403
} else {

cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrLayoutBB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ZarrLayoutBB(Variable v2, Section wantSection, RandomAccessFile raf) {
6262
for (int i = 0; i < ndims; i++) {
6363
Dimension dim = v2.getDimension(i);
6464
// round up nchunks if not evenly divisible by chunk size
65-
this.nChunks[i] = (int) Math.ceil(dim.getLength() / this.chunkSize[i]);
65+
this.nChunks[i] = (int) Math.ceil((double) dim.getLength() / this.chunkSize[i]);
6666
this.totalNChunks *= nChunks[i];
6767
}
6868

0 commit comments

Comments
 (0)