-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from olyutorskii/release/v2.101.2
Release/v2.101.2
- Loading branch information
Showing
19 changed files
with
1,356 additions
and
1,173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/main/java/io/github/olyutorskii/doubdabc/BcdArrays.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* License : The MIT License | ||
* Copyright(c) 2017 olyutorskii | ||
*/ | ||
|
||
package io.github.olyutorskii.doubdabc; | ||
|
||
/** | ||
* BCD array utilities but experimental. | ||
*/ | ||
public final class BcdArrays { | ||
|
||
private static final int INT_SLOTS = | ||
Integer.SIZE / BcdUtils.BCD_BITSIZE; | ||
|
||
private static final int MSB_INTMASK = 0b1 << (Integer.SIZE - 1); | ||
private static final int LSB_INTMASK = 0b1; | ||
|
||
private static final int BCD_MASK = | ||
(0b1 << BcdUtils.BCD_BITSIZE) - 1; | ||
private static final int ARABICUC_MASK = 0b0011_0000; | ||
|
||
|
||
/** | ||
* Hidden constructor. | ||
*/ | ||
private BcdArrays(){ | ||
assert false; | ||
} | ||
|
||
|
||
/** | ||
* Convert int value to Arabic-decimal character sequence. | ||
* | ||
* <p>Output nothing if value 0. | ||
* | ||
* <p>sign-bit is treated as unsigned. | ||
* There is no minus-sign output. | ||
* | ||
* <p>DDA implementations without any instance field. | ||
* | ||
* @param iVal int value | ||
* @param cbuf char output | ||
* @param offset output start offset | ||
* @return output length | ||
*/ | ||
public static int int2ArabicArray(final int iVal, | ||
final char[] cbuf, final int offset){ | ||
int iHigh = 0b0; | ||
int iLow = 0b0; | ||
|
||
boolean skipLeading = true; | ||
boolean noHalfCarry = true; | ||
int sig = 0; | ||
|
||
for(int bitCt = 0; bitCt < Integer.SIZE; bitCt++){ | ||
final int scanMask = MSB_INTMASK >>> bitCt; | ||
final int bitAppear = iVal & scanMask; | ||
|
||
if(skipLeading){ | ||
if(bitAppear == 0b0) continue; | ||
skipLeading = false; | ||
} | ||
sig++; | ||
|
||
int bqVal; | ||
int shiftedBcd; | ||
|
||
bqVal = BcdUtils.toBiQuinary(iLow); | ||
shiftedBcd = bqVal << 1; | ||
|
||
if(bitAppear == 0b0){ | ||
iLow = shiftedBcd; | ||
}else{ | ||
iLow = shiftedBcd | LSB_INTMASK; | ||
} | ||
|
||
// through iHigh | ||
// if iLow has 8-bcd "67108863"(2^26-1) or lower | ||
if(sig < 27) continue; | ||
|
||
int halfCarry = bqVal & MSB_INTMASK; | ||
|
||
if(noHalfCarry){ | ||
if(halfCarry == 0b0) continue; | ||
noHalfCarry = false; | ||
} | ||
|
||
bqVal = BcdUtils.toBiQuinary(iHigh); | ||
shiftedBcd = bqVal << 1; | ||
|
||
if(halfCarry == 0b0){ | ||
iHigh = shiftedBcd; | ||
}else{ | ||
iHigh = shiftedBcd | LSB_INTMASK; | ||
} | ||
} | ||
|
||
int cidx = offset; | ||
final int clzLow; | ||
|
||
if(iHigh == 0b0){ | ||
clzLow = BcdUtils.clzNibble(iLow); | ||
}else{ | ||
clzLow = 0; | ||
|
||
final int clzHigh = BcdUtils.clzNibble(iHigh); | ||
|
||
for(int bcdCt = clzHigh; bcdCt < INT_SLOTS; bcdCt++){ | ||
final int nibble = (iHigh >>> ((7 - bcdCt) << 2)) & BCD_MASK; | ||
final char decimalCh = (char)(nibble | ARABICUC_MASK); | ||
cbuf[cidx++] = decimalCh; | ||
} | ||
} | ||
|
||
for(int bcdCt = clzLow; bcdCt < INT_SLOTS; bcdCt++){ | ||
final int nibble = (iLow >>> ((7 - bcdCt) << 2)) & BCD_MASK; | ||
final char decimalCh = (char)(nibble | ARABICUC_MASK); | ||
cbuf[cidx++] = decimalCh; | ||
} | ||
|
||
return cidx - offset; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.