Example usage for java.lang Float NEGATIVE_INFINITY

List of usage examples for java.lang Float NEGATIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Float NEGATIVE_INFINITY.

Prototype

float NEGATIVE_INFINITY

To view the source code for java.lang Float NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type float .

Usage

From source file:org.nd4j.linalg.util.ArrayUtil.java

public static short fromFloat(float v) {
    if (Float.isNaN(v))
        return (short) 0x7fff;
    if (v == Float.POSITIVE_INFINITY)
        return (short) 0x7c00;
    if (v == Float.NEGATIVE_INFINITY)
        return (short) 0xfc00;
    if (v == 0.0f)
        return (short) 0x0000;
    if (v == -0.0f)
        return (short) 0x8000;
    if (v > 65504.0f)
        return 0x7bff; // max value supported by half float
    if (v < -65504.0f)
        return (short) (0x7bff | 0x8000);
    if (v > 0.0f && v < 5.96046E-8f)
        return 0x0001;
    if (v < 0.0f && v > -5.96046E-8f)
        return (short) 0x8001;

    final int f = Float.floatToIntBits(v);

    return (short) (((f >> 16) & 0x8000) | ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00)
            | ((f >> 13) & 0x03ff));
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#add(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *//*  w  w w  . j  av  a  2s . c  o  m*/
@SuppressWarnings("unchecked")
@Test
public void testAddObjectNumberClassOfT() {
    assertEquals("null", null, add(null, null, null));
    assertEquals("null", null, add("123.456", null, null));
    assertEquals("null", null, add("123.456", 1, null));
    assertEquals("null", null, add("", 10, null));
    assertEquals("null", null, add(null, 10, null));
    assertEquals("null", null, add(123.456, 10, null));
    assertEquals("123 + .456: Float", (Object) 123.456f, add(123, .456, Float.class));
    assertEquals("123 + .456: Float", (Object) Float.class, add(123, .456, Float.class).getClass());
    assertEquals("123 + .456: Float", (Object) Float.class, add(123L, .456d, Float.class).getClass());
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            assertEquals("null: default: " + type.getSimpleName(), valueOf(null, typeOfN),
                    add(null, null, typeOfN));
            assertEquals("123.456: " + type.getSimpleName(), valueOf(123 + .456, typeOfN),
                    add("123", .456, typeOfN));
            assertEquals("NaN + 123: " + type.getSimpleName(), valueOf(123, typeOfN), add("NaN", 123, typeOfN));
            assertEquals("123 + NaN: " + type.getSimpleName(), valueOf("123", typeOfN),
                    add("123", Float.NaN, typeOfN));
            assertEquals("invalid + 123: " + type.getSimpleName(), valueOf(123, typeOfN),
                    add("not a number", 123, typeOfN));
            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("-Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("-Infinity", 123, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("Infinity", 123, typeOfN));

            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 - Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.NEGATIVE_INFINITY, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 + Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.POSITIVE_INFINITY, typeOfN));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:ExposedFloat.java

public boolean action(Event evt, Object arg) {

    if (evt.target instanceof Button) {
        String bname = (String) arg;
        if (bname.equals(incrementButtonString)) {

            ++value;//from w  w w .j  av  a 2  s  .co m
        } else if (bname.equals(decrementButtonString)) {

            --value;
        } else if (bname.equals(multByZeroButtonString)) {

            value *= (float) 0.0;
        } else if (bname.equals(piButtonString)) {

            value = (float) Math.PI;
        } else if (bname.equals(positiveInfinityButtonString)) {

            value = Float.POSITIVE_INFINITY;
        } else if (bname.equals(negativeInfinityButtonString)) {

            value = Float.NEGATIVE_INFINITY;
        } else if (bname.equals(maximumButtonString)) {

            value = Float.MAX_VALUE;
        } else if (bname.equals(minimumButtonString)) {

            value = Float.MIN_VALUE;
        } else if (bname.equals(notANumberButtonString)) {

            value = Float.NaN;
        } else if (bname.equals(changeSignButtonString)) {

            value *= -1.0;
        } else if (bname.equals(doubleButtonString)) {

            value *= 2.0;
        } else if (bname.equals(halveButtonString)) {

            value /= 2.0;
        }
        updateNumberFields();
        enableDisableButton(maximumButton, Float.MAX_VALUE);
        enableDisableButton(minimumButton, Float.MIN_VALUE);
        enableDisableButton(positiveInfinityButton, Float.POSITIVE_INFINITY);
        enableDisableButton(negativeInfinityButton, Float.NEGATIVE_INFINITY);
        enableDisableButton(piButton, (float) Math.PI);
        enableDisableButton(notANumberButton, Float.NaN);
        if (!notANumberButton.isEnabled()) {
            if (!Float.isNaN(value)) {
                notANumberButton.enable();
            }
        } else if (Float.isNaN(value)) {
            notANumberButton.disable();
        }
    }
    return true;
}

From source file:org.fnlp.nlp.similarity.train.WordCluster.java

/**
 * merge clusters//  www.  j  ava2s .com
 */
public void mergeCluster() {
    int maxc1 = -1;
    int maxc2 = -1;
    float maxL = Float.NEGATIVE_INFINITY;
    TIntIterator it1 = slots.iterator();
    while (it1.hasNext()) {
        int i = it1.next();
        TIntIterator it2 = slots.iterator();
        //         System.out.print(i+": ");
        while (it2.hasNext()) {
            int j = it2.next();

            if (i >= j)
                continue;
            //            System.out.print(j+" ");
            float L = calcL(i, j);
            //            System.out.print(L+" ");
            if (L > maxL) {
                maxL = L;
                maxc1 = i;
                maxc2 = j;
            }
        }
        //         System.out.println();
    }
    //      if(maxL == Float.NEGATIVE_INFINITY )
    //         return;

    merge(maxc1, maxc2);
}

From source file:ffx.xray.parsers.MTZWriter.java

/**
 * <p>/*from  ww  w. j  a v  a 2  s .  c o m*/
 * write</p>
 */
public void write() {
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileOutputStream fileOutputStream;
    DataOutputStream dataOutputStream;

    try {
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(format("\n Writing MTZ HKL file: \"%s\"\n", fileName));
            logger.info(sb.toString());
        }

        fileOutputStream = new FileOutputStream(fileName);
        dataOutputStream = new DataOutputStream(fileOutputStream);

        byte bytes[] = new byte[80];
        int offset = 0;
        int writeLen = 0;

        int iMapData;
        float fMapData;

        // Header.
        StringBuilder sb = new StringBuilder();
        sb.append("MTZ ");
        dataOutputStream.writeBytes(sb.toString());

        // Header offset.
        int headerOffset = n * nCol + 21;
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        byteBuffer.order(byteOrder).putInt(headerOffset);

        // Machine code: double, float, int, uchar
        // 0x4441 for LE, 0x1111 for BE
        if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            iMapData = 0x4441;
        } else {
            iMapData = 0x1111;
        }
        byteBuffer.order(byteOrder).putInt(iMapData);
        dataOutputStream.write(bytes, offset, 8);

        sb = new StringBuilder();
        sb.append(" ");
        sb.setLength(68);
        dataOutputStream.writeBytes(sb.toString());

        // Data.
        Vector<String> colname = new Vector<>(nCol);
        char colType[] = new char[nCol];
        double res[] = new double[2];
        res[0] = Double.POSITIVE_INFINITY;
        res[1] = Double.NEGATIVE_INFINITY;
        float colMinMax[][] = new float[nCol][2];
        for (int i = 0; i < nCol; i++) {
            colMinMax[i][0] = Float.POSITIVE_INFINITY;
            colMinMax[i][1] = Float.NEGATIVE_INFINITY;
        }
        ReflectionSpline sigmaASpline = new ReflectionSpline(reflectionList, refinementData.sigmaa.length);
        int col = 0;

        colname.add("H");
        colType[col++] = 'H';
        colname.add("K");
        colType[col++] = 'H';
        colname.add("L");
        colType[col++] = 'H';
        writeLen += 12;

        if (mtzType != MTZType.FCONLY) {
            colname.add("FO");
            colType[col++] = 'F';
            colname.add("SIGFO");
            colType[col++] = 'Q';
            colname.add("FreeR");
            colType[col++] = 'I';
            writeLen += 12;
        }

        if (mtzType != MTZType.DATAONLY) {
            colname.add("Fs");
            colType[col++] = 'F';
            colname.add("PHIFs");
            colType[col++] = 'P';
            colname.add("Fc");
            colType[col++] = 'F';
            colname.add("PHIFc");
            colType[col++] = 'P';
            writeLen += 16;
        }

        if (mtzType == MTZType.ALL) {
            colname.add("FOM");
            colType[col++] = 'W';
            colname.add("PHIW");
            colType[col++] = 'P';
            colname.add("SigmaAs");
            colType[col++] = 'F';
            colname.add("SigmaAw");
            colType[col++] = 'Q';
            colname.add("FWT");
            colType[col++] = 'F';
            colname.add("PHWT");
            colType[col++] = 'P';
            colname.add("DELFWT");
            colType[col++] = 'F';
            colname.add("PHDELWT");
            colType[col++] = 'P';
            writeLen += 32;
        }

        for (HKL ih : reflectionList.hkllist) {
            col = 0;
            int i = ih.index();

            // Skip the 0 0 0 reflection.
            if (ih.h() == 0 && ih.k() == 0 && ih.l() == 0) {
                continue;
            }

            double ss = Crystal.invressq(crystal, ih);
            res[0] = min(ss, res[0]);
            res[1] = max(ss, res[1]);

            // HKL first (3)
            fMapData = ih.h();
            colMinMax[col][0] = min(fMapData, colMinMax[0][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[0][1]);
            byteBuffer.rewind();
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;

            fMapData = ih.k();
            colMinMax[col][0] = min(fMapData, colMinMax[1][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[1][1]);
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;

            fMapData = ih.l();
            colMinMax[col][0] = min(fMapData, colMinMax[2][0]);
            colMinMax[col][1] = max(fMapData, colMinMax[2][1]);
            byteBuffer.order(byteOrder).putFloat(fMapData);
            col++;

            if (mtzType != MTZType.FCONLY) {
                // F/sigF (2)
                fMapData = (float) refinementData.getF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) refinementData.getSigF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // Free R (1)
                fMapData = (float) refinementData.getFreeR(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }

            if (mtzType == MTZType.FCONLY) {
                // Fs (2)
                fMapData = (float) refinementData.fsF(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fsPhi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // Fc (unscaled!) (2)
                fMapData = (float) refinementData.fcF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) Math.toDegrees(refinementData.fcPhi(i));
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }

            if (mtzType == MTZType.ALL) {
                // Fs (2)
                fMapData = (float) refinementData.fsF(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fsPhi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // Fctot (2)
                fMapData = (float) refinementData.fcTotF(i);
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fcTotPhi(i));
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // FOM/phase (2)
                fMapData = (float) refinementData.fomphi[i][0];
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.fomphi[i][1]);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // Spline setup.
                double fh = spline.f(ss, refinementData.spline);
                double sa = sigmaASpline.f(ss, refinementData.sigmaa);
                double wa = sigmaASpline.f(ss, refinementData.sigmaw);

                // sigmaA/w (2)
                fMapData = (float) sa;
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) wa;
                if (!isNaN(fMapData)) {
                    colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                    colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                }
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;

                // Map coeffs (4).
                fMapData = (float) refinementData.FoFc2F(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.FoFc2Phi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) refinementData.foFc1F(i);
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
                fMapData = (float) toDegrees(refinementData.foFc1Phi(i));
                colMinMax[col][0] = min(fMapData, colMinMax[col][0]);
                colMinMax[col][1] = max(fMapData, colMinMax[col][1]);
                byteBuffer.order(byteOrder).putFloat(fMapData);
                col++;
            }

            dataOutputStream.write(bytes, offset, writeLen);
        }

        // Header.
        sb = new StringBuilder();
        sb.append("VERS MTZ:V1.1 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss ");
        sb = new StringBuilder();
        sb.append("TITLE FFX output: " + sdf.format(now));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append(String.format("NCOL %8d %12d %8d", nCol, n, 0));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("SORT    0    0    0    0    0 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        char cdata = spaceGroup.shortName.charAt(0);
        if (cdata == 'H') {
            cdata = 'R';
        }
        sb.append(String.format("SYMINF %3d %2d %c %5d %22s %5s", spaceGroup.getNumberOfSymOps(),
                spaceGroup.numPrimitiveSymEquiv, cdata, spaceGroup.number, "'" + spaceGroup.shortName + "'",
                spaceGroup.pointGroupName));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        for (int i = 0; i < spaceGroup.symOps.size(); i++) {
            sb = new StringBuilder();
            sb.append("SYMM ");
            SymOp symop = spaceGroup.symOps.get(i);
            sb.append(symop.toXYZString());
            while (sb.length() < 80) {
                sb.append(" ");
            }
            dataOutputStream.writeBytes(sb.toString());
        }

        sb = new StringBuilder();
        sb.append(String.format("RESO %8.6f%13s%8.6f", res[0], " ", res[1]));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("VALM NAN ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("NDIF        1 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("PROJECT       1 project ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("CRYSTAL       1 crystal ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("DATASET       1 dataset ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        for (int j = 0; j < nCol; j++) {
            sb = new StringBuilder();
            sb.append(String.format("COLUMN %-30s %c %17.4f %17.4f    1", colname.get(j), colType[j],
                    colMinMax[j][0], colMinMax[j][1]));
            dataOutputStream.writeBytes(sb.toString());
        }

        sb = new StringBuilder();
        sb.append(String.format("CELL %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", crystal.a, crystal.b, crystal.c,
                crystal.alpha, crystal.beta, crystal.gamma));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append(String.format("DCELL %9d %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", 1, crystal.a, crystal.b,
                crystal.c, crystal.alpha, crystal.beta, crystal.gamma));
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("DWAVEL        1    1.00000 ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("END ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        sb = new StringBuilder();
        sb.append("MTZENDOFHEADERS ");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dataOutputStream.writeBytes(sb.toString());

        dataOutputStream.close();
    } catch (Exception e) {
        String message = "Fatal exception evaluating structure factors.\n";
        logger.log(Level.SEVERE, message, e);
    }
}

From source file:net.pms.util.Rational.java

/**
 * Returns an instance that represents the value of {@code value}.
 *
 * @param value the value.//from   ww  w.  j a  v a2  s. c o m
 * @return An instance that represents the value of {@code value}.
 */
@Nonnull
public static Rational valueOf(float value) {
    if (value == Float.POSITIVE_INFINITY) {
        return POSITIVE_INFINITY;
    }
    if (value == Float.NEGATIVE_INFINITY) {
        return NEGATIVE_INFINITY;
    }
    if (Float.isNaN(value)) {
        return NaN;
    }
    return valueOf(BigDecimal.valueOf(value));
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat32EncodeNegInfinity() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT32.writeValue(Float.NEGATIVE_INFINITY, g);
    g.flush();//from   ww w  .jav  a 2 s . c  om
    assertEquals("\"-Infinity\"", out.toString());
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat32DecodeNegInfinity() throws IOException {
    JsonParser p = f.createParser("\"-Infinity\"");
    p.nextToken();//  www  . j  av a  2 s  .co  m
    assertTrue(Float.NEGATIVE_INFINITY == JsonValueHandler.FLOAT32.readValue(p));
}

From source file:org.shaman.terrain.polygonal.GraphToHeightmap.java

private void addVoronoiNoise() {
    float cellSize = (float) size / (float) VORONOI_CELL_COUNT;
    List<Vector3f> pointList = new ArrayList<>();
    for (int x = 0; x < VORONOI_CELL_COUNT; ++x) {
        for (int y = 0; y < VORONOI_CELL_COUNT; ++y) {
            float nx = x * cellSize;
            float ny = y * cellSize;
            for (int i = 0; i < VORONOI_POINTS_PER_CELL; ++i) {
                pointList.add(new Vector3f(nx + rand.nextFloat() * cellSize, ny + rand.nextFloat() * cellSize,
                        rand.nextFloat()));
            }/*from  ww  w. j a v a  2 s  .c  om*/
        }
    }
    Vector3f[] points = pointList.toArray(new Vector3f[pointList.size()]);
    LOG.info("voronoi point created");
    //now cycle through cells and find influencing hills
    Heightmap tmp = new Heightmap(size);
    Vector3f first = new Vector3f();
    Vector3f second = new Vector3f();
    float min = Float.POSITIVE_INFINITY;
    float max = Float.NEGATIVE_INFINITY;
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            //sort points by distance to (x,y)
            final float px = x;
            final float py = y;
            findClosestTwoPoints(points, px, py, first, second);
            assert (dist(first, px, py) <= dist(second, px, py));
            //calc height
            float v = -1 * dist(first, px, py) + 1 * dist(second, px, py);
            tmp.setHeightAt(x, y, v);
            min = Math.min(v, min);
            max = Math.max(v, max);
        }
    }
    //normalize
    float factor = 1f / (max - min);
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            float h = tmp.getHeightAt(x, y);
            tmp.setHeightAt(x, y, (h - min) * factor);
        }
    }
    LOG.info("voronoi cells calculated");
    //distort
    Noise distortionNoise = new Noise(rand.nextLong());
    Heightmap tmp2 = new Heightmap(size);
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            float s = x / (float) size;
            float t = y / (float) size;
            float ss = (float) (s + VORONOI_DISTORTION_AMPLITUDE * 2 * distortionNoise
                    .noise(s * VORONOI_DISTORTION_FREQUENCY, t * VORONOI_DISTORTION_FREQUENCY, 0));
            float tt = (float) (t + VORONOI_DISTORTION_AMPLITUDE * 2 * distortionNoise
                    .noise(s * VORONOI_DISTORTION_FREQUENCY, t * VORONOI_DISTORTION_FREQUENCY, 3.4));
            float v = tmp.getHeightInterpolating(ss * size, tt * size);
            tmp2.setHeightAt(x, y, v);
        }
    }
    LOG.info("voronoi cells distorted");
    //apply
    for (int x = 0; x < size; ++x) {
        for (int y = 0; y < size; ++y) {
            float amplitude = noise[x][y][2];
            heightmap.adjustHeightAt(x, y, amplitude * tmp.getHeightAt(x, y) * VORONOI_SCALE);
        }
    }

    LOG.info("voronoi noise added");
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.TestApplicationMasterService.java

@Test(timeout = 1200000)
public void testProgressFilter() throws Exception {
    MockRM rm = new MockRM(conf);
    rm.start();//from   w  w w  .  java 2  s  . c  o  m

    // Register node1
    MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB);

    // Submit an application
    RMApp app1 = rm.submitApp(2048);

    nm1.nodeHeartbeat(true);
    RMAppAttempt attempt1 = app1.getCurrentAppAttempt();
    MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
    am1.registerAppAttempt();

    AllocateRequestPBImpl allocateRequest = new AllocateRequestPBImpl();
    List<ContainerId> release = new ArrayList<ContainerId>();
    List<ResourceRequest> ask = new ArrayList<ResourceRequest>();
    allocateRequest.setReleaseList(release);
    allocateRequest.setAskList(ask);

    allocateRequest.setProgress(Float.POSITIVE_INFINITY);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 1) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }

    allocateRequest.setProgress(Float.NaN);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 0) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }

    allocateRequest.setProgress((float) 9);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 1) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }

    allocateRequest.setProgress(Float.NEGATIVE_INFINITY);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 0) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }

    allocateRequest.setProgress((float) 0.5);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 0.5) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }

    allocateRequest.setProgress((float) -1);
    am1.allocate(allocateRequest);
    while (attempt1.getProgress() != 0) {
        LOG.info("Waiting for allocate event to be handled ...");
        sleep(100);
    }
}