Subject: [Cellar] expressing a float in text

From: Dave Rice <[email-masked]>
Date: Sat, 13 Feb 2016 13:50:19 -0500

To accommodate the float range expressions in Frank’s color work, I’m expanding the “Expression of range” [1] section to accommodate floats (currently it only discusses signed and unsigned integers). Frank’s use of float ranges are quite simple, such as 0.0 to 1.0; however, in defining a method to document a float range, I think the definition should work for any possible float value.

Is there an standard document to point to for how to represent a float value as text? i.e. I’m familiar with float values in text such as 3.88E-4 but where it this style of expression defined?

Best Regards,
Dave Rice

[1] https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#expression-of-range

---

From: Reto Kromer <[email-masked]>
Date: Sat, 13 Feb 2016 19:57:18 +0100

Dave Rice wrote:

>Is there an standard document to point to for how to
>represent a float value as text? i.e. I’m familiar with
>float values in text such as 3.88E-4 but where it this
>style of expression defined?

IEEE 754-2008?

Best regards, Reto

AV Preservation by reto.ch
chemin du Suchet 5 | 1024 Ecublens | Switzerland
Web: http://reto.ch | Twitter: @retoch

---

From: Nithin Mathew Kurien <[email-masked]>
Date: Sun, 14 Feb 2016 00:54:18 +0530

Hi,

Not sure if it is suitable in this context, but C99 supports writing floats
accurately in hexadecimal notation (
http://www.exploringbinary.com/hexadecimal-floating-point-constants/). The
advantage of hexadecimal notation is that values can be represented
accurately, unlike representions like 1.67e-3, which will result in
rounding errors when converted from decimal to the native binary form. With
a C99 compiler like GCC, we can output the hexadecimal form of any float.

double num  = 1.55e1;
printf("%a", num);

would output

0x1.fp3

which is equal to (1 + 15/16) * 2^3.

Thanks and regards,
Nithin

On Sun, Feb 14, 2016 at 12:20 AM, Dave Rice <[email-masked]> wrote:

> To accommodate the float range expressions in Frank’s color work, I’m
> expanding the “Expression of range” [1] section to accommodate floats
> (currently it only discusses signed and unsigned integers). Frank’s use of
> float ranges are quite simple, such as 0.0 to 1.0; however, in defining a
> method to document a float range, I think the definition should work for
> any possible float value.
>
> Is there an standard document to point to for how to represent a float
> value as text? i.e. I’m familiar with float values in text such as 3.88E-4
> but where it this style of expression defined?
>
> Best Regards,
> Dave Rice
>
> [1]
> https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#expression-of-range
> _______________________________________________
> Cellar mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/cellar
>

---

From: Steve Lhomme <[email-masked]>
Date: Sun, 14 Feb 2016 18:02:24 +0100

2016-02-13 20:24 GMT+01:00 Nithin Mathew Kurien <[email-masked]>:
> accurately in hexadecimal notation
> (http://www.exploringbinary.com/hexadecimal-floating-point-constants/). The
> accurately, unlike representions like 1.67e-3, which will result in rounding
> errors when converted from decimal to the native binary form. With a C99
> compiler like GCC, we can output the hexadecimal form of any float.
>
> double num  = 1.55e1;
> printf("%a", num);
>
> would output
>
> 0x1.fp3
>

I agree that since floats are not always bit exact a format that
accurately interprets the machine value anytime would be better. Not
sure if the C99 representation works for other languages too.

We might have a machine representation and text representation for
each value so it's easy to read and clean to interpret.

>> method to document a float range, I think the definition should work for any
>> possible float value.
>>

-- 
Steve Lhomme
Matroska association Chairman

---

From: Dave Rice <[email-masked]>
Date: Sun, 14 Feb 2016 14:11:05 -0500

> On Feb 13, 2016, at 2:24 PM, Nithin Mathew Kurien <[email-masked]> wrote:
> 
> Hi,
> 
> Not sure if it is suitable in this context, but C99 supports writing floats accurately in hexadecimal notation (http://www.exploringbinary.com/hexadecimal-floating-point-constants/ <http://www.exploringbinary.com/hexadecimal-floating-point-constants/>). The advantage of hexadecimal notation is that values can be represented accurately, unlike representions like 1.67e-3, which will result in rounding errors when converted from decimal to the native binary form. With a C99 compiler like GCC, we can output the hexadecimal form of any float.
> 
> double num  = 1.55e1;
> printf("%a", num);
> 
> would output
> 
> 0x1.fp3
> 

For values such as 0.0 and 1.0, wouldn't the C99 notation be different depending on if the float is expressed as a single or double? Currently an EBML float could be either 4 or 8 bytes and the choice of float length is not part of the element definition. If we use C99 notation we may be implying whether the float is single or double and should consider saying so in the definition.
Dave

> Thanks and regards,
> Nithin
> 
> 
> On Sun, Feb 14, 2016 at 12:20 AM, Dave Rice <[email-masked] <mailto:[email-masked]>> wrote:
> [1] https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#expression-of-range <https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#expression-of-range>
> [email-masked] <mailto:[email-masked]>
> https://www.ietf.org/mailman/listinfo/cellar <https://www.ietf.org/mailman/listinfo/cellar>
>

---

From: Nithin Mathew Kurien <[email-masked]>
Date: Thu, 18 Feb 2016 21:04:29 +0530

This representation is supported in C++, Java and Python too. If
compatibility with other languages is a concern, perhaps we can include a
small conversion function in libEBML? The strtod() and strtof() functions
in the GNU C Library do this conversion.

Thanks and regards,
Nithin

On Sun, Feb 14, 2016 at 10:32 PM, Steve Lhomme <[email-masked]> wrote:

> rounding

---

From: Nithin Mathew Kurien <[email-masked]>
Date: Thu, 18 Feb 2016 21:05:21 +0530

Yes, the notations would be different. Single floats would have 6
hexadecimal digits in the mantissa, whereas double floats would have 13. I
would suggest defining all EBML floats as doubles, because of the greater
range and precision available.

Thanks and regards,
Nithin

On Mon, Feb 15, 2016 at 12:41 AM, Dave Rice <[email-masked]> wrote:

> Not sure if it is suitable in this context, but C99 supports writing
> floats accurately in hexadecimal notation (
> http://www.exploringbinary.com/hexadecimal-floating-point-constants/).
> The advantage of hexadecimal notation is that values can be represented
> For values such as 0.0 and 1.0, wouldn't the C99 notation be different
> depending on if the float is expressed as a single or double? Currently an
> EBML float could be either 4 or 8 bytes and the choice of float length is
> not part of the element definition. If we use C99 notation we may be
> implying whether the float is single or double and should consider saying
> so in the definition.
> Dave
>
> Thanks and regards,
> Nithin
>
>

---

From: Steve Lhomme <[email-masked]>
Date: Sun, 28 Feb 2016 15:14:43 +0100

> range and precision available.

Since Matroska floating point numbers can be double precision, a
program handling Matroska has to work in double-precision (or lose
some accuracy with floats). So I think it's ok to assume that floats
are defined as double-precision in the specs.

Also, do we allow NaN as a possible default value ?

>> floats accurately in hexadecimal notation
>> implying whether the float is single or double and should consider saying so
>> in the definition.
>> Dave
>>
>> Thanks and regards,
>> Nithin
>>
>>

---

From: Dave Rice <[email-masked]>
Date: Sun, 28 Feb 2016 09:49:02 -0500

> On Feb 28, 2016, at 9:14 AM, Steve Lhomme <[email-masked]> wrote:
> 

I don't think any existing MKV floats are defined as single or double precision. The element definitions just label them as 'float' and in the context of EBML a float can mean either 0, 4, or 8 bytes.

Is there reason to refine the specs to define elements as particular types of floats?

> Also, do we allow NaN as a possible default value ?

I don't think so. Nitpicky, but do you have a sentence or reference to define what NaN signifies.
Dave

---

From: Steve Lhomme <[email-masked]>
Date: Sun, 28 Feb 2016 16:04:29 +0100

> I don't think any existing MKV floats are defined as single or double precision. The element definitions just label them as 'float' and in the context of EBML a float can mean either 0, 4, or 8 byt…

That's the way they are stored. But when handling the data in the
processor, you either use double or float (or both if you don't like
reusing code) that the processor uses. I'd assume that implies using
double-precision as it's the most demanding case. So if there's a
binary format representation in addition to the text one, it should
probably be a double precision one.

> I don't think so. Nitpicky, but do you have a sentence or reference to define what NaN signifies.

No. In the context of EBML it may not be needed as not putting a
default value means it's undefined anyway. For math data storage (not
in the context of Matroska) it may make sense though. It's fine to
have a variable Nan. We may also allow ∞ and -∞. Not sure how I would
code that in libebml though...