Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for floating point operations #2742

Merged
merged 3 commits into from
Jun 16, 2019

Conversation

smortex
Copy link
Contributor

@smortex smortex commented May 21, 2019

This PR is about supporting math expression using floating-point values. The code is published for review for now, because some decisions might need to be discussed. I plan to amend the commits to address the issues and comments raised by the syslog-ng community, and remove the [Do not merge] tag when I consider the changes to be ready.

Fixes #2734

@kira-syslogng
Copy link
Contributor

This user does not have permission to start the build. Can one of the admins verify this patch and start the build?
(admin: you have the next options (make sure you checked the code):
"ok to test" to accept this pull request (and further changes) for testing
"test this please" for a one time test run
"add to whitelist" add author of a Pull Request to whitelist (globally, be careful, it means this user can trigger kira for any PR)
do nothing -> CI won't start)

1 similar comment
@kira-syslogng
Copy link
Contributor

This user does not have permission to start the build. Can one of the admins verify this patch and start the build?
(admin: you have the next options (make sure you checked the code):
"ok to test" to accept this pull request (and further changes) for testing
"test this please" for a one time test run
"add to whitelist" add author of a Pull Request to whitelist (globally, be careful, it means this user can trigger kira for any PR)
do nothing -> CI won't start)

@Kokan
Copy link
Collaborator

Kokan commented May 21, 2019

@kira-syslogng ok to test

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@smortex smortex force-pushed the floating-point-operations branch from 69f8e08 to c082655 Compare May 21, 2019 23:23
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@Kokan
Copy link
Collaborator

Kokan commented May 23, 2019

@smortex I brough up this feature to the team, and we want to discuss it. It may take some time, but I hope not later than next Wednesday.

@smortex
Copy link
Contributor Author

smortex commented May 23, 2019

Sure, thanks you for taking care of it! I started "the easy way" and I guess a lot of topics will be raised, such as:

  • should sum, minimum, maximum & co be updated to support floats;
  • should the system be reworked to minimize the impact of roundings when the result of an operation is used in another operation;
  • etc.

Maintainers of the project can push commits to my branch, feel free to do so, but please send me a heads-up in this case so that I do not git push -f and loose your changes unexpectedly 😉

@Kokan Kokan added this to the syslog-ng-3.22 milestone May 29, 2019
@Kokan
Copy link
Collaborator

Kokan commented May 29, 2019

I tried to summarise the result of that conversation:

A short summary of the discussion about this topic:

Re/defining the arithmetic operations:

The way how operation should be defined: like the one you proposed in your PR, the one in the issue( new operations for float).
The conclusion on that was that your proposal is the solution we want to have. (Mainly because of the next point, and because it is natural on some level.)

Impact on current configurations

With your version it is not an issue, as float was not supported before and operations with float resulted invalid/unwanted result (like NaN)

Storage method/1

There is a recurring idea that nv-pairs should have more sophisticated way to store different types (other then the string representation).
This discussion was halted as it is kinda complex, and that would explode the work needed to be done now (also could be splitted as well).

Storage method/2

Your proposal stores the float in a string representation. (this is somewhat connected to the next topic)
That introduces a precision syslog-ng could handle, which must be defined and compatible what float/double precision could do.

Operations error propagation

A brief discussion about the errors each operation could introduce, or just the converting into string.
The conclusion on this was that syslog-ng is not a scientific tool, and as such the error propagation is a best effort basis.
Meaning if some issue raises on the matter, we can open a discussion to solve or state that won't solve such an issue;
as likely such discussion will never come up.

What it means for this PR:

  • The way you defined the operation extension is OK
  • The precision/storage need some improvement

Copy link
Collaborator

@Kokan Kokan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please in case of all [optional] comment either reply won't fix or do the change; I am fine with both.

modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/tests/test_basicfuncs.c Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
@smortex smortex force-pushed the floating-point-operations branch from 314e96e to 919909d Compare May 31, 2019 21:50
@smortex

This comment has been minimized.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

Kokan
Kokan previously approved these changes Jun 1, 2019
@smortex
Copy link
Contributor Author

smortex commented Jun 2, 2019

@Kokan, just to be sure, can you please confirm that your approval has value of "ok for squashing the commits and moving on to the next step"?

@Kokan
Copy link
Collaborator

Kokan commented Jun 2, 2019

@smortex yes for the squash; but if by next step you mean merging the PR, then no. as that requires at least two approver.

@smortex
Copy link
Contributor Author

smortex commented Jun 2, 2019

Sure! By "next step" I meant further work on the PR ;-)

Make it possible to use the mathematic operators with floating point
values.  Behave like the C programming language:
  - if both operands are integers, then compute and return an integer;
  - if any of the operands is a floating-point number, return a
    floating-point result.

$(/ 3   2)   #=> 1
$(/ 3.0 2)   #=> 1.500000
$(/ 3   2.0) #=> 1.500000
$(/ 3.0 2.0) #=> 1.500000
With the ability to compute values with floating points, we need to be
able to round results.
@smortex
Copy link
Contributor Author

smortex commented Jun 2, 2019

I reordered the commits, fixed and squashed the commits after rebasing on top of the master branch. I pushed the two modified commits one by one in order to trigger two builds. Let's see how is goes 😉

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@smortex smortex force-pushed the floating-point-operations branch from 1b582ba to 4d6f1a0 Compare June 3, 2019 13:01
@smortex smortex changed the title [Do not merge] Add support for floating point operations Add support for floating point operations Jun 3, 2019
@smortex
Copy link
Contributor Author

smortex commented Jun 3, 2019

Thanks! I added the optional precision argument to round, and reached a complete coverage of my use-case.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@smortex smortex force-pushed the floating-point-operations branch 2 times, most recently from 6752a82 to 6454988 Compare June 3, 2019 17:51
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@smortex smortex force-pushed the floating-point-operations branch from 6454988 to b0e5659 Compare June 3, 2019 18:43
@kira-syslogng
Copy link
Contributor

Build SUCCESS

modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Outdated Show resolved Hide resolved
modules/basicfuncs/numeric-funcs.c Show resolved Hide resolved
modules/basicfuncs/tests/test_basicfuncs.c Show resolved Hide resolved
@smortex
Copy link
Contributor Author

smortex commented Jun 4, 2019

I added a bunch of commit that address the problems you spotted. Thanks!

@kira-syslogng
Copy link
Contributor

Build FAILURE

1 similar comment
@kira-syslogng
Copy link
Contributor

Build FAILURE

@Kokan
Copy link
Collaborator

Kokan commented Jun 6, 2019

@smortex please feel free to fixup the changes in the next step (if you agree with my comment on your commit), and from my side it is good to go.

Allow an optional second argument to the round template to set the
precision of the rounding.  The default is 0 (output a natural number)
but values up to 20 are accepted.

The limit of 20 was set in accordance with the precision used internally
for computations.
@smortex smortex force-pushed the floating-point-operations branch from 80db31e to 3ba54e8 Compare June 6, 2019 19:59
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@smortex
Copy link
Contributor Author

smortex commented Jun 6, 2019

Thanks @Kokan I squashed the last commits into a single one. It looks like the "default" kira build fails, but I cannot access the system. Is there something I can fix myself?

@Kokan
Copy link
Collaborator

Kokan commented Jun 6, 2019

@smortex please ignore the default kira.

@bazsi
Copy link
Collaborator

bazsi commented Jun 7, 2019 via email

@Kokan
Copy link
Collaborator

Kokan commented Jun 7, 2019

(@smortex I'll do some stuff here to make default green, you still can ignore)

@Kokan
Copy link
Collaborator

Kokan commented Jun 7, 2019

@kira-syslogng retest this please

@kira-syslogng
Copy link
Contributor

Build FAILURE

@Kokan
Copy link
Collaborator

Kokan commented Jun 12, 2019

@kira-syslogng retest this please

@kira-syslogng
Copy link
Contributor

Build SUCCESS

Copy link
Collaborator

@bazsi bazsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@Kokan Kokan merged commit f3298e8 into syslog-ng:master Jun 16, 2019
@smortex smortex deleted the floating-point-operations branch June 16, 2019 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for operation on floats
4 participants