Examples of HalfPrecisionFloat


Examples of co.nstant.in.cbor.model.HalfPrecisionFloat

    }

    @Override
    public HalfPrecisionFloat decode(int initialByte) throws CborException {
        int bits = nextSymbol() << 8 | nextSymbol();
        return new HalfPrecisionFloat(toFloat(bits));
    }
View Full Code Here

Examples of co.nstant.in.cbor.model.HalfPrecisionFloat

    return new UnicodeString(string);
  }

  protected DataItem convert(float value) {
    if (isHalfPrecisionEnough(value)) {
      return new HalfPrecisionFloat(value);
    } else {
      return new SinglePrecisionFloat(value);
    }
  }
View Full Code Here

Examples of co.nstant.in.cbor.model.HalfPrecisionFloat

  private boolean isHalfPrecisionEnough(float value) {
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      HalfPrecisionFloatEncoder encoder = new HalfPrecisionFloatEncoder(
          null, outputStream);
      encoder.encode(new HalfPrecisionFloat(value));
      ByteArrayInputStream inputStream = new ByteArrayInputStream(
          outputStream.toByteArray());
      HalfPrecisionFloatDecoder decoder = new HalfPrecisionFloatDecoder(
          null, inputStream);
      HalfPrecisionFloat halfPrecisionFloat = decoder.decode(0);
      return value == halfPrecisionFloat.getValue();
    } catch (CborException cborException) {
      return false;
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.