diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java index aa4f237d..6a6dc6d3 100755 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java @@ -2028,4 +2028,25 @@ public static AbstractCobolField funcExceptionStatus() { } return currField; } + + /** + * cob_intr_fraction_partの実装 + * + * @param srcfield + * @return + */ + public static AbstractCobolField funcFractionPart(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 18, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + currField.moveFrom(srcfield); + return currField; + } } diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java index 38a40b6a..8765f6e6 100644 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java @@ -40,19 +40,7 @@ public byte[] getBytes() { @Override public String getString() { - CobolFieldAttribute thisAttr = this.getAttribute(); - int flag = thisAttr.isFlagHaveSign() ? CobolFieldAttribute.COB_FLAG_HAVE_SIGN : 0; - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC, - thisAttr.getDigits(), - thisAttr.getScale(), - flag, - thisAttr.getPic()); - CobolDataStorage storage = new CobolDataStorage(thisAttr.getDigits()); - CobolNumericField numericField = new CobolNumericField(thisAttr.getDigits(), storage, attr); - numericField.moveFrom(this); - return numericField.getString(); + return String.format("%.18f", this.getDouble()); } @Override diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java index 168b4a4e..6d2ac2dd 100644 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java @@ -382,9 +382,7 @@ private void moveBinaryToDisplay(AbstractCobolField field) { private void moveDoubleToDisplay(AbstractCobolField field) { CobolFieldAttribute thisAttr = this.getAttribute(); - double val = Math.abs(field.getDouble() * thisAttr.getScale()); - String formatter = "%0" + thisAttr.getDigits() + "." + thisAttr.getScale() + "f"; - String valString = String.format(formatter, val).replace(".", ""); + double val = Math.abs(field.getDouble()); int startIndex = 0; if (thisAttr.isFlagHaveSign() && thisAttr.isFlagSignLeading() @@ -392,7 +390,7 @@ private void moveDoubleToDisplay(AbstractCobolField field) { startIndex = 1; } CobolDataStorage dstStorage = this.getDataStorage().getSubDataStorage(startIndex); - dstStorage.memcpy(valString, thisAttr.getDigits()); + dstStorage.memcpy(String.valueOf(val), thisAttr.getDigits()); this.putSign(field.getSign() >= 0 ? 1 : -1); } diff --git a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index a81cecd1..fae0918e 100755 --- a/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -166,7 +166,7 @@ public class CobolFile { protected static String file_open_name; protected static byte[] file_open_buff = new byte[1024]; - protected static final String[] prefix = { "DD_", "dd_", "" }; + protected static final String[] prefix = {"DD_", "dd_", ""}; protected static final int NUM_PREFIX = prefix.length; protected static int eop_status = 0; @@ -175,16 +175,16 @@ public class CobolFile { private static List file_cache = new ArrayList(); protected static int[] status_exception = { - 0, - CobolExceptionId.COB_EC_I_O_AT_END, - CobolExceptionId.COB_EC_I_O_INVALID_KEY, - CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR, - CobolExceptionId.COB_EC_I_O_LOGIC_ERROR, - CobolExceptionId.COB_EC_I_O_RECORD_OPERATION, - CobolExceptionId.COB_EC_I_O_FILE_SHARING, - CobolExceptionId.COB_EC_I_O, - CobolExceptionId.COB_EC_I_O, - CobolExceptionId.COB_EC_I_O_IMP + 0, + CobolExceptionId.COB_EC_I_O_AT_END, + CobolExceptionId.COB_EC_I_O_INVALID_KEY, + CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR, + CobolExceptionId.COB_EC_I_O_LOGIC_ERROR, + CobolExceptionId.COB_EC_I_O_RECORD_OPERATION, + CobolExceptionId.COB_EC_I_O_FILE_SHARING, + CobolExceptionId.COB_EC_I_O, + CobolExceptionId.COB_EC_I_O, + CobolExceptionId.COB_EC_I_O_IMP }; public String select_name; public byte[] file_status; @@ -232,8 +232,7 @@ public void setLinorkeyptr(Linage ptr) { this.linorkeyptr = ptr; } - public CobolFile() { - } + public CobolFile() {} public CobolFile( String selectName, @@ -290,8 +289,7 @@ public CobolFile( } /** - * libcob/fileio.cのsave_statusの実装 - * RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. + * libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. * * @param status * @param fnstatus @@ -355,7 +353,8 @@ protected boolean file_linage_check() { Linage lingptr = getLinorkeyptr(); lingptr.setLinLines(lingptr.getLinage().getInt()); - outer: { + outer: + { if (lingptr.getLinLines() < 1) { break outer; } @@ -768,22 +767,25 @@ public int open_(String filename, int mode, int sharing) throws IOException { fp = FileChannel.open(Paths.get(filename), StandardOpenOption.READ); break; case COB_OPEN_OUTPUT: - fp = FileChannel.open( - Paths.get(filename), - StandardOpenOption.WRITE, - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); + fp = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.WRITE, + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING); break; case COB_OPEN_I_O: - fp = FileChannel.open( - Paths.get(filename), - StandardOpenOption.READ, - StandardOpenOption.WRITE, - StandardOpenOption.CREATE); + fp = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.READ, + StandardOpenOption.WRITE, + StandardOpenOption.CREATE); break; case COB_OPEN_EXTEND: - fp = FileChannel.open( - Paths.get(filename), StandardOpenOption.APPEND, StandardOpenOption.CREATE); + fp = + FileChannel.open( + Paths.get(filename), StandardOpenOption.APPEND, StandardOpenOption.CREATE); break; default: break; @@ -1073,7 +1075,8 @@ public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) } String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_WRITE, this, null, rec.getDataStorage(), fnstatus, openMode, null, null) != 0) { + if (invokeFun(COB_IO_WRITE, this, null, rec.getDataStorage(), fnstatus, openMode, null, null) + != 0) { return; } diff --git a/tests/run.src/functions.at b/tests/run.src/functions.at index 3c7e5419..07b08fa6 100644 --- a/tests/run.src/functions.at +++ b/tests/run.src/functions.at @@ -674,7 +674,6 @@ AT_CHECK([java prog], [0], AT_CLEANUP AT_SETUP([FUNCTION FRACTION-PART]) -AT_CHECK([${SKIP_TEST}]) AT_DATA([prog.cob], [ IDENTIFICATION DIVISION. @@ -1035,8 +1034,7 @@ AT_CHECK([java prog], [0], AT_CLEANUP -AT_SETUP([FUNCTION MIDRANGE]) -AT_CHECK([${SKIP_TEST}]) +AT_SETUP([FUNCTION MIDRANGE(calculation result is negative)]) AT_DATA([prog.cob], [ IDENTIFICATION DIVISION. @@ -1056,6 +1054,46 @@ AT_CHECK([java prog], [0], AT_CLEANUP +AT_SETUP([FUNCTION MIDRANGE(calculation result is positive)]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + DISPLAY FUNCTION MIDRANGE ( 3 14 0 8 3 ) + END-DISPLAY. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], +[7.000000000000000000 +]) + +AT_CLEANUP + +AT_SETUP([FUNCTION MIDRANGE(calculation result is decimal)]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + DISPLAY FUNCTION MIDRANGE ( 2 2 3 9 ) + END-DISPLAY. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], +[5.500000000000000000 +]) + +AT_CLEANUP + AT_SETUP([FUNCTION MIN]) AT_DATA([prog.cob], [