博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
gdb ldexp_带有Python示例的math.ldexp()方法
阅读量:2532 次
发布时间:2019-05-11

本文共 2659 字,大约阅读时间需要 8 分钟。

gdb ldexp

Python math.ldexp()方法 (Python math.ldexp() method)

math.ldexp() method is a library method of math module, it is used to calculate expression x*(2**i), where x is a mantissa and i is an exponent. It accepts two numbers (x is either float or integer, i is an integer) and returns the result of the expression x*(2**i)).

math.ldexp()方法数学模块的库方法,用于计算表达式x *(2 ** i) ,其中x是尾数, i是指数。 它接受两个数字( x是浮点数或整数, i是整数),并返回表达式x *(2 ** i)的结果

Note: There is a method in math module that is used to get the pair of mantissa and exponent in a tuple. The math.ldexp() method is an inverse of . In other words, w can understand that returns mantissa and exponent of a number and math.ldexp() method reforms/creates the number again using x – mantissa and i – exponent.

注意: 数学模块中有一种方法可用于获取元组中的尾数对和指数对。 math.ldexp()方法与相反。 换句话说,w可以理解返回数字的尾数和指数,而math.ldexp()方法再次使用x –尾数和i –指数来重整 /创建数字。

Syntax of math.ldexp() method:

math.ldexp()方法的语法:

math.ldexp(x, i)

Parameter(s): x, i – the numbers to be calculated the expression "x*(2**i)".

参数: x,i –要计算的数字,表达式为“ x *(2 ** i)”

Return value: float – it returns a float value that is the result of expression "x*(2**i)".

返回值: float-它返回一个浮点值,该值是表达式“ x *(2 ** i)”的结果

Example:

例:

Input:    x = 2    i = 3    # function call    print(math.ldexp(x,i))    Output:    16.0 # (x*(2**i) = (2*(2**3)) = 16

Python代码演示math.ldexp()方法的示例 (Python code to demonstrate example of math.ldexp() method)

# python code to demonstrate example of # math.ldexp() method# importing math moduleimport math# numberx = 2i = 3# math.ldexp() methodprint(math.ldexp(x,i))x = 0i = 0# math.ldexp() methodprint(math.ldexp(x,i))x = 0.625i = 4# math.ldexp() methodprint(math.ldexp(x,i))x = -0.639625i = 4# math.ldexp() methodprint(math.ldexp(x,i))

Output

输出量

16.00.010.0-10.234

区分math.frexp()和math.ldexp()方法的Python代码 (Python code to differentiate the math.frexp() and math.ldexp() methods)

Here, we have a number a and finding it's mantissa and exponent as a pair (x, i), and again making the same number by using math.ldexp() method that calculates the expression (x*(2**i))

在这里,我们有一个数字a,并找到它的尾数和指数对(x,i) ,然后再次使用math.ldexp()方法来计算表达式(x *(2 ** i)

# python code to demonstrate example of # math.ldexp() method# importing math moduleimport matha = 10frexp_result = math.frexp(a)print("frexp() result: ", frexp_result)# extracing its valuesx = frexp_result[0]i = frexp_result[1]print("Extracted part from frexp_result...")print("x = ", x)print("i = ", i)# now using method ldexp()ldexp_result = math.ldexp(x,i)print("ldexp() result: ", ldexp_result)

Output

输出量

frexp() result:  (0.625, 4)Extracted part from frexp_result...x =  0.625i =  4ldexp() result:  10.0

翻译自:

gdb ldexp

转载地址:http://ruxzd.baihongyu.com/

你可能感兴趣的文章
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JS中各种跳转解析
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>
Ecust OJ
查看>>
P3384 【模板】树链剖分
查看>>
Thrift源码分析(二)-- 协议和编解码
查看>>
考勤系统之计算工作小时数
查看>>
4.1 分解条件式
查看>>
Equivalent Strings
查看>>
flume handler
查看>>
收藏其他博客园主写的代码,学习加自用。先表示感谢!!!
查看>>
H5 表单标签
查看>>
su 与 su - 区别
查看>>
C语言编程-9_4 字符统计
查看>>