question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adaptive Expressions Float division

See original GitHub issue

Is your feature request related to a problem? Please describe. While microsoft/botbuilder-js#3527 is about fixing explicit floats, it doesn’t address wanting to get a float as a return object from a division operation.

Consider the following expression: div(11, 2) the result would be 5. What if we wanted 5.5? As of the currently, I think it’d be impossible to achieve. div(11.0, 2) and even div(float("11.0"), float(2)) won’t work, even with the microsoft/botbuilder-js#3527 fix. Even then, if those two situations were accounted for somehow, it wouldn’t fix when we wanted to explicitly get a precise number from a division operation.

Describe the solution you’d like A new prebuilt function I believe is the only solution. Something like divPrecise(11, 2, 2) where the last argument would be the number of decimal places to return. I believe the return object would have to be a string to accurately return the correct value. That function should return 5.50

Describe alternatives you’ve considered I think extending the existing div function could work, but I don’t think it would be backward compatible given the current tests that exist, e.g. div(5, 2, 2) where each argument is an additional division operation.

Additional context Just that I am really liking this library, and hope that I can use it for this case. I’m happy to take a stab at this function, but since it’s a decent amount of work, would like to have the core team validate that it’s not already possible using other methods I may have overlooked.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
garyprettycommented, May 11, 2021

I would like @Stevenic / @chrimc62 / @tomlm to comment on this issue as to the approach for resolving it. i.e. new function vs breaking change. My gut says we shouldn’t be introducing a breaking change. Perhaps another option would be to provide an additional optional argument into the div function to specify the output type, but I will let folks chime in here.

Once we understand the scope of the approach here we can look to add into planning.

1reaction
Danieladucommented, Apr 7, 2021

@stefangomez yes. It would break some tests. There indeed some gaps between different languages naturally. We try the best to align between languages. If the logic of div is changed from “C# mode” into “js mode”, the code of C# side should be changed at the same time. It’s a breaking change. We would discuss with team mates to decide whether to implement it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adaptive expressions prebuilt functions in Bot Framework SDK
Learn about the available prebuilt functions in adaptive expressions ordered by their general purpose.
Read more >
Efficient floating-point division with constant integer divisors
Let me restart for the third time. We are trying to accelerate q = x / y. where y is an integer constant,...
Read more >
Floating-point arithmetic - Wikipedia
In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the ...
Read more >
Adaptive Precision Floating-Point Arithmetic and Fast Robust ...
This article presents two techniques for writing fast implementations of extended precision calculations like these, and demonstrates them with ...
Read more >
Division Operators in Python - GeeksforGeeks
However, the division operator '/' returns always a float value. ... value which is less than or equal to a specified expression or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found