-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ Contents: | |
:maxdepth: 2 | ||
|
||
hello | ||
logic | ||
integers | ||
floats | ||
strings | ||
pythagoras | ||
guiindex | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||