Maybe it is better to use Decimal floating point numbers instead of the default binary floating point numbers. Another possiblity would be to use mm and an int type to store the length.
For the length attribute, the wrong representation of decimal numbers can become a problem: When accumulating the element ending position for a FODO lattice
the length of the first cell gets calculated correctly. Cells beginning with the 6th cell have the wrong length:
First cell:
------------
end 0.75 D1
end 2.25 B1
end 2.8 D1
end 3.1999999999999997 Q2
end 3.75 D1
end 5.25 B1
end 5.8 D1
end 6.0 Q1
...
6th cell:
----------
end 30.200000000000003 Q1
end 30.750000000000004 D1
end 32.25 B1
end 32.8 D1
end 33.199999999999996 Q2
...
8th cell:
end 47.799999999999976 D1
end 47.99999999999998 Q1
The problem is, that this is inconsistent with the length attribute of the ring:
which, returns the "correct" length. This is because the Lattice object will add the length of all its sub_lattices (which have length 6.0) instead of adding the length of all its elements (like shown above).
Maybe it is better to use
Decimal
floating point numbers instead of the default binary floating point numbers. Another possiblity would be to use mm and anint
type to store the length.For the
length
attribute, the wrong representation of decimal numbers can become a problem: When accumulating the element ending position for a FODO latticethe length of the first cell gets calculated correctly. Cells beginning with the 6th cell have the wrong length:
The problem is, that this is inconsistent with the
length
attribute of the ring:which, returns the "correct" length. This is because the
Lattice
object will add the length of all itssub_lattices
(which have length6.0
) instead of adding the length of all its elements (like shown above).