File: README.md

package info (click to toggle)
python-autobahn 17.10.1%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,452 kB
  • sloc: python: 22,598; javascript: 2,705; makefile: 497; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Decimal Calculator Service
==========================

This example demonstrates a WAMP component providing a decimal calculator service.

A browser based UI is included which uses AutobahnJS to access
the decimal calculator service.

Further, since it's a standard WAMP service, any WAMP client can use
the service. You could access it i.e. from a native
Android app via AutobahnAndroid or from a remote AutobahnPython based
client.


Running
-------

Run the calculator backend component by doing

    python calculator.py

and open

    http://localhost:8080/

in your browser.


Background
----------

The calculator service performs correct decimal arithmetic, something not available
(out of the box) in JavaScript.


To see this just try

    console.log(1.1 + 2.2);

in your browser. The output is:

    3.3000000000000003

which is not the result a person would expect when using a calculator.


The reason is that JavaScript implements all numbers as IEEE doubles, which is
a binary floating-point type. Since it's a base-2 floating point, certain numbers
cannot be represented exactly. To be precise, any rational number with a divisor
having a prime factor other than 2 cannot be represented exactly. Decimal arithmetic
uses a base-10, which has prime factors 2 and 5, and consequently all rationals which
have no other prime factors in their divisor other than 2 or 5 can be represented exactly.


Anyway, I hope you get what I mean;)