Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-3841: [Spec] Align the specification of the way to encode NaN to the actual implementations #2463

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/content/en/docs/++version++/Specification/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ Primitive types are encoded in binary as follows:
|64 | 80 01|
|...|...|

* a _float_ is written as 4 bytes. The float is converted into a 32-bit integer using a method equivalent to Java's [floatToIntBits](https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html#floatToIntBits-float-) and then encoded in little-endian format.
* a _double_ is written as 8 bytes. The double is converted into a 64-bit integer using a method equivalent to Java's [doubleToLongBits](https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#doubleToLongBits-double-) and then encoded in little-endian format.
* a _float_ is written as 4 bytes. The float is converted into a 32-bit integer using a method equivalent to Java's [floatToRawIntBits](https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html#floatToRawIntBits-float-) and then encoded in little-endian format.
* a _double_ is written as 8 bytes. The double is converted into a 64-bit integer using a method equivalent to Java's [doubleToRawLongBits](https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#doubleToRawLongBits-double-) and then encoded in little-endian format.
* _bytes_ are encoded as a long followed by that many bytes of data.
* a _string_ is encoded as a long followed by that many bytes of UTF-8 encoded character data.
For example, the three-character string "foo" would be encoded as the long value 3 (encoded as hex 06) followed by the UTF-8 encoding of 'f', 'o', and 'o' (the hex bytes 66 6f 6f):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class BinaryDecoder
/// <summary>
/// A float is written as 4 bytes.
/// The float is converted into a 32-bit integer using a method equivalent to
/// Java's floatToIntBits and then encoded in little-endian format.
/// Java's floatToRawIntBits and then encoded in little-endian format.
/// </summary>
/// <returns></returns>
public float ReadFloat()
Expand All @@ -56,7 +56,7 @@ public float ReadFloat()
/// <summary>
/// A double is written as 8 bytes.
/// The double is converted into a 64-bit integer using a method equivalent to
/// Java's doubleToLongBits and then encoded in little-endian format.
/// Java's doubleToRawLongBits and then encoded in little-endian format.
/// </summary>
/// <returns>A double value.</returns>
public double ReadDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class BinaryDecoder
/// <summary>
/// A float is written as 4 bytes.
/// The float is converted into a 32-bit integer using a method equivalent to
/// Java's floatToIntBits and then encoded in little-endian format.
/// Java's floatToRawIntBits and then encoded in little-endian format.
/// </summary>
/// <returns></returns>
public float ReadFloat()
Expand All @@ -49,7 +49,7 @@ public float ReadFloat()
/// <summary>
/// A double is written as 8 bytes.
/// The double is converted into a 64-bit integer using a method equivalent to
/// Java's doubleToLongBits and then encoded in little-endian format.
/// Java's doubleToRawLongBits and then encoded in little-endian format.
/// </summary>
/// <returns>A double value.</returns>
public double ReadDouble()
Expand Down
4 changes: 2 additions & 2 deletions lang/csharp/src/apache/main/IO/BinaryEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void WriteLong(long value)
/// <summary>
/// A float is written as 4 bytes.
/// The float is converted into a 32-bit integer using a method equivalent to
/// Java's floatToIntBits and then encoded in little-endian format.
/// Java's floatToRawIntBits and then encoded in little-endian format.
/// </summary>
/// <param name="value"></param>
public void WriteFloat(float value)
Expand All @@ -99,7 +99,7 @@ public void WriteFloat(float value)
/// <summary>
///A double is written as 8 bytes.
///The double is converted into a 64-bit integer using a method equivalent to
///Java's doubleToLongBits and then encoded in little-endian format.
///Java's doubleToRawLongBits and then encoded in little-endian format.
/// </summary>
/// <param name="value"></param>
public void WriteDouble(double value)
Expand Down
8 changes: 4 additions & 4 deletions lang/py/avro/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ def read_float(self) -> float:
"""
A float is written as 4 bytes.
The float is converted into a 32-bit integer using a method equivalent to
Java's floatToIntBits and then encoded in little-endian format.
Java's floatToRawIntBits and then encoded in little-endian format.
"""
return float(STRUCT_FLOAT.unpack(self.read(4))[0])

def read_double(self) -> float:
"""
A double is written as 8 bytes.
The double is converted into a 64-bit integer using a method equivalent to
Java's doubleToLongBits and then encoded in little-endian format.
Java's doubleToRawLongBits and then encoded in little-endian format.
"""
return float(STRUCT_DOUBLE.unpack(self.read(8))[0])

Expand Down Expand Up @@ -453,15 +453,15 @@ def write_float(self, datum: float) -> None:
"""
A float is written as 4 bytes.
The float is converted into a 32-bit integer using a method equivalent to
Java's floatToIntBits and then encoded in little-endian format.
Java's floatToRawIntBits and then encoded in little-endian format.
"""
self.write(STRUCT_FLOAT.pack(datum))

def write_double(self, datum: float) -> None:
"""
A double is written as 8 bytes.
The double is converted into a 64-bit integer using a method equivalent to
Java's doubleToLongBits and then encoded in little-endian format.
Java's doubleToRawLongBits and then encoded in little-endian format.
"""
self.write(STRUCT_DOUBLE.pack(datum))

Expand Down
8 changes: 4 additions & 4 deletions lang/ruby/lib/avro/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def read_long
def read_float
# A float is written as 4 bytes.
# The float is converted into a 32-bit integer using a method
# equivalent to Java's floatToIntBits and then encoded in
# equivalent to Java's floatToRawIntBits and then encoded in
# little-endian format.
read_and_unpack(4, 'e')
end

def read_double
# A double is written as 8 bytes.
# The double is converted into a 64-bit integer using a method
# equivalent to Java's doubleToLongBits and then encoded in
# equivalent to Java's doubleToRawLongBits and then encoded in
# little-endian format.
read_and_unpack(8, 'E')
end
Expand Down Expand Up @@ -203,15 +203,15 @@ def write_long(n)

# A float is written as 4 bytes.
# The float is converted into a 32-bit integer using a method
# equivalent to Java's floatToIntBits and then encoded in
# equivalent to Java's floatToRawIntBits and then encoded in
# little-endian format.
def write_float(datum)
@writer.write([datum].pack('e'))
end

# A double is written as 8 bytes.
# The double is converted into a 64-bit integer using a method
# equivalent to Java's doubleToLongBits and then encoded in
# equivalent to Java's doubleToRawLongBits and then encoded in
# little-endian format.
def write_double(datum)
@writer.write([datum].pack('E'))
Expand Down