计算数字的标准化和工程科学记数法的最快算法
测试用例:
35000
->该数字的标准化科学记数法为 3.5 * 10E4
->工程符号为 35 * 10E3
执行此操作的简单算法将不断将数字除以 10,直到我们获得所需的符号。然而,这意味着该算法将是 O(零的数量)。我们可以做得更好吗?
Test case :
35000
-> a normalized scientific notation of the number would be 3.5 * 10E4
-> the engineering notation would be 35 * 10E3
A simple algorithm that does this would keep dividing the number by 10 until we get the notations required. However this would mean the algorithm would be O(number of zeros). Can we do better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于打印人类友好的浮点数表示的经典论文可以在此处阅读。它太复杂了,无法在此处的答案中作为代码进行讨论。
The classic paper on the subject of printing human-friendly representations of floating point numbers can be read here. It's much too complex to be discussed as code in an answer here.