Math tan(45) rounding error

18 views
Skip to first unread message

Kelvin Lawrence

unread,
Apr 12, 2018, 6:07:33 PM4/12/18
to Gremlin-users
I realize this is a "feature" of the underlying Java math classes most likely but it might be worth adding a warning to the docs for the 'math' step that this can happen:

g.inject(Math.toRadians(45)).math('tan(_)')


0.9999999999999999


Cheers
Kelvin

Robert Dale

unread,
Apr 13, 2018, 8:47:42 AM4/13/18
to gremli...@googlegroups.com
Is this really unexpected in computing?

Robert Dale

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/ce0a4feb-bf3b-4700-9047-eab297d84451%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kelvin Lawrence

unread,
Apr 13, 2018, 9:38:29 AM4/13/18
to Gremlin-users
You make a very fair point Robert. I know that Python and Ruby would yield the same and it is true this is essentially the limitation of floating point numbers. I guess my point is that I tend to err towards over documenting things based on the assumption that not everyone will know to expect this result. I totally agree this is a very minor nit!

Kelvin


On Friday, April 13, 2018 at 7:47:42 AM UTC-5, Robert Dale wrote:
Is this really unexpected in computing?

Robert Dale

On Thu, Apr 12, 2018 at 6:07 PM, Kelvin Lawrence <kelvin.r...@gmail.com> wrote:
I realize this is a "feature" of the underlying Java math classes most likely but it might be worth adding a warning to the docs for the 'math' step that this can happen:

g.inject(Math.toRadians(45)).math('tan(_)')


0.9999999999999999


Cheers
Kelvin

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages