Skip to content

Commit

Permalink
Doc [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Nov 29, 2017
1 parent 05473b5 commit 42690e1
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
69 changes: 69 additions & 0 deletions doc/tutorial/floats.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Floating Point Numbers
======================

Floating point literals are local approximations to reals.
Local means close to zero. Floats are dense near zero and
loose precision far from it.

Type
----

We lift the main floating point type, `double` from C.

.. code-block:: felix
type double = "double";
It is a double precision floating point representation
usually conformat to IEEE specifications.

Literals
--------

Floating literals have two parts, a decimal number
known as the mantissa, and a power of 10 known as the
exponent.

.. code-block:: felix
12.34
12.34E-4
The mantissa must contain a decimal point with a digit on either
side. The exponent is optional, and consists of the letter `E`
or `e` followed by a small decimal integer literal, or a + sign
or minus sign, and a small decimal integer literal.

If the exponent is present, the mantissa is multiplied by
10 raised to the power of the signed integer part exponent.

Operations
----------

Floating numbers support negation with prefix `-`, addition
with infix `+`, subtraction with infix `-`, multiplication
with infix `*` and division with infix `/` as well as
many other operations given by functions in the library.

It is also possible to perform comparisons, equality `==`,
inequality `!=`, less than `<`, less than or equal to `<=`,
greater than `>` and greater than or equal to `>=`. However
these comparisons reflect floating point arithmentic
which only approximates real arithmetic. Do not be suprised
if the formula

.. code-block:: felix
1.0 / 3.0 * 3.0 == 1.0
is false. To remedy this properly requires a deep knowledge
of numerical analysis. Felix helps by providing the function
`abs` which can be used like this:

.. code-block:: felix
abs ( 1.0 / 3.0 * 3.0 - 1.0) < 1.0e-3
to check the result is with about 3 decimal places of 1.0.

2 changes: 2 additions & 0 deletions doc/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Contents:
:maxdepth: 2

hello
logic
integers
floats
strings
pythagoras
guiindex
Expand Down
57 changes: 57 additions & 0 deletions doc/tutorial/logic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Logic Type Bool
===============

Felix provides a type for simple logic which tradiationally
is called `bool` after mathematician George Bool.

Type
----

We lift the type from C++ as usual:

.. code-block:: felix
type bool = "std::bool";
Constants
---------

There two predefined constants, `true` and `false`.

Operations
----------

The prefix operator `not` provides negation, infix
`and` conjunction, and infix `or` disjunction,
with weak precedences, of decreasing strength.

.. code-block:: felix
not a and b or c
is parsed as

.. code-block:: felix
((not a) and b) or c
These operators are all weaker than the comparisons they often
take as arguments, so that


.. code-block:: felix
a < b and b < c
is parsed as

.. code-block:: felix
(a < b) and (b < c)

0 comments on commit 42690e1

Please sign in to comment.