Skip to content

Commit

Permalink
0.7 allowing decimal floats
Browse files Browse the repository at this point in the history
  • Loading branch information
tef committed Aug 4, 2012
1 parent e1d8db5 commit d235657
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 37 deletions.
30 changes: 18 additions & 12 deletions doc/todo
@@ -1,27 +1,33 @@

next commits:
ruby:
avoid to_sym
form input support
default value support
better ordered dictionaries
relative url handling
error mapping
blob support for returns, etc

python:
relative url handling (+tests for url less forms in resources)
new encoder/decoder w/ dependencies & resolver / constructors
maybe py2/
error mapping
client error /server error
handle unknown content types as blob
http 1.1 server
method names in method not in url mapping
handled, but not used.
http 1.1 server
refactor?
glyph.client, glyph, resource, server
py.test over unittest
blob support for returns, etc
client/server if allow="*"

ruby:
done: avoid to_sym
form input support
somewhat: no names or default value support
better ordered dictionaries
done
relative url handling
error mapping

spec:
allow ordered dicts in places, including form args/data
flesh out collection type - add useful methods?
done: allow ordered dicts in places, including form args/data
rejected: flesh out collection type - add useful methods?


speculative commits:
Expand Down
6 changes: 5 additions & 1 deletion py/glyph/encoding.py
Expand Up @@ -295,7 +295,11 @@ def _read_one(self, fh, c, resolver, blobs):
return _read_until(fh, END_ITEM, parse=int)[0]

elif c == FLT:
return _read_until(fh, END_ITEM, parse=float.fromhex)[0]
f = _read_until(fh, END_ITEM)[0]
if 'x' in f:
return float.fromhex(f)
else:
return float(f)

elif c == SET:
first = read_first(fh)
Expand Down
6 changes: 5 additions & 1 deletion rb/lib/glyph.rb
Expand Up @@ -484,7 +484,11 @@ def self.parse_one(scanner,url,blobs)
TimeDelta.iso_parse(per)
when ?f
num = scanner.scan_until(/;/)
num.chop.hex_to_f
if num.index('x')
num.chop.hex_to_f
else
num.chop.to_f
end
when ?u
num = scanner.scan_until(/[:;]/)
if num.end_with? ':'
Expand Down
65 changes: 42 additions & 23 deletions spec/glyph_spec.rst
Expand Up @@ -18,6 +18,8 @@ and translates instances and methods to pages and forms.
The client browses the server, using forms to invoke
methods.

0.7 is not backwards compatible with 0.6 or earlier.


.. contents::

Expand Down Expand Up @@ -46,7 +48,7 @@ and collections (list, set, dict). ::
dict {1:2, 2:4} Di1;i2;i3;i4;;
ordered_dict ordered(1:2, 2:4) Oi1;i2;i3;i4;;
singleton nil true false N; T; F;
float 0.5 f0x1.0000000000000p-1;
float 0.5 f0x1.0000000000000p-1; or f0.5;
datetime 1970-1-1 00:00 UTC d1970-01-01T00:00:00.000Z;
timedelta 3 days pP0Y0M3DT0H0M0S;

Expand Down Expand Up @@ -220,36 +222,44 @@ encoders MUST present all leading 0s.
float
-----

floating point numbers cannot easily be represented
in decimal without loss of accuracy. instead of using an endian
dependent binary format, we use the hex format from C99::
floating point numbers can be represented in decimal or
hexadecimal. hexadecimal floats were introduced by C99,
and provide a way for accurate, endian free
representation of floats. for example::

float hex

0.5 0x1.0p-1
-0.5 -0x1.0p-1
+0.0 0x0p0
-0.0 -0x0p0
1.729 0x1.ba9fbe76c8b44p+0
float hex decimal

details on the encoding and decoding of hex floats is covered in an appendix.
Hex floats are supported natively by a number of languages.
glyph uses hex floats, except for special values: nan and infinity::
0.5 0x1.0p-1 f0.5;
-0.5 -0x1.0p-1 f-0.5;
+0.0 0x0p0 f+0.0;
-0.0 -0x0p0 f-0.0;
1.729 0x1.ba9fbe76c8b44p+0 f1.729;

float :== 'f' hex_float ';'
hex floats are `<sign.?>0x<hex>.<hex>e<sign><decimal>`, where
the first number is the fractional part in hex, and the latter is the exponent
in decimal. details on the encoding and decoding of hex floats is covered in an appendix.

glyph uses hex or decimal floats, except for the special floating
point values: nan and infinity::

float :== 'f' hex_float ';' | 'f' decimal_float ';' | 'f' named_float ';'

float encoding
0.5 f0x1.0p-1;
-0.5 f-0x1.0p-1;
0.0 f0x0p0;
float encoding
0.5 f0x1.0p-1; or f0.5;
-0.5 f-0x1.0p-1; or f-0.5;
0.0 f0x0p0; or f0.0;

Infinity finf; fInfinity; finfinity;
-Infinity f-inf; f-infinity; f-Infinity;
NaN fnan; fNaN;
Infinity finf; or fInfinity; or finfinity;
-Infinity f-inf; or f-infinity; or f-Infinity;
NaN fnan; or fNaN;

decoders MUST ignore case.
encoders MUST use 'inf' or 'infinity', not 'infin', 'in', etc.

decoders MUST support hex and decimal floats. encoders
SHOULD use hex floats instead of decimal.


node
----
Expand Down Expand Up @@ -564,13 +574,20 @@ links, forms and other extensions.
reserved extensions
-------------------

extensions with the names: integer, unicode, string, bytearray, float, datetime, timedelta, nil, true, false, list, set, dict, dict, ordered_dict, node, extension, blob, bool are reserved.
the following extension names are reserved, and should not be used for
application or vendor specific extensions::

integer, unicode, string, bytearray, float, datetime,
timedelta, nil, true, false, list, set, dict,
ordered_dict, node, extension, blob, bool,
request, response


http mapping
============

glyph-rpc uses HTTP/1.1
glyph-rpc uses HTTP/1.1, although mappings to other protocols,
or transports is possible.

mime type
---------
Expand Down Expand Up @@ -954,6 +971,8 @@ before embracing hypermedia.

- 0.7

- allow decimal floats because i'm not that cruel

planned changes
---------------

Expand Down

0 comments on commit d235657

Please sign in to comment.