fix long cast to double

- the result of dividing long with long resulted in loss of precision both for network and IO
- unit tests included

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
license headers added

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>