float(‘inf‘)与float(‘-inf‘)

float('inf')float('-inf')

在Python中,float('inf')是一种表示正无穷大的方法。inf是无穷大(infinity)的缩写。在数学中,无穷大是比任何实数都大的数。在Python中,它是float类型,可以用于比较操作或作为数学运算中的一个边界值。

positive_infinity = float('inf')

# 比较操作
print(positive_infinity > 1000)      # 输出: True
print(positive_infinity > 99999)     # 输出: True

# 用作边界值
min_value = float('inf')
numbers = [5, 3, 9, -1, 10]

for number in numbers:
    if number < min_value:
        min_value = number

print(min_value)  # 输出: -1

Python同样支持负无穷大,表示方法是float('-inf'),它表示的是一个比任何其他实数都小的数:

negative_infinity = float('-inf')

# 比较操作
print(negative_infinity < -1000)     # 输出: True
print(negative_infinity < -99999)    # 输出: True

# 用作边界值
max_value = float('-inf')
numbers = [5, 3, 9, -1, 10]

for number in numbers:
    if number > max_value:
        max_value = number

print(max_value)  # 输出: 10

在使用无穷大进行数学运算时需要小心,因为某些运算可能会产生不是真正数字的结果,例如NaN(不是一个数字)

# 无穷大加上无穷大仍然是无穷大
print(positive_infinity + positive_infinity)  # 输出: inf

# 无穷大乘以2仍然是无穷大
print(positive_infinity * 2)  # 输出: inf

# 无穷大减去无穷大不是一个数字(NaN)
print(positive_infinity - positive_infinity)  # 输出: nan

# 任何数字除以无穷大得0
print(1 / positive_infinity)  # 输出: 0.0

在做比较和数学运算时,无穷大在许多方面的行为就像是一个非常大或非常小的数字,但它仍然有一些特殊的行为规则。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
SimIt-ARM-3.0 给予命令行ARM指令模拟器,短小精悍,是研究ARM处理器的好工具,该模拟器既可以运行用户级别的ELF程序,又可以模拟运行Linux操作系统;提供了简单易用的调试命令,可以逐条跟踪指令的执行。 SimIt-ARM-3.0-gk-20150902.tar.bz2 HowTo 0.what is SimIt-ARM-3.0 SimIt-ARM 3.0 is an instruction-set simulator that runs both system-level and user-level ARM programs, for more about it please read user's guide file. 1.how to build tar jxvf SimIt-ARM-3.0-gk-20150902.tar.bz2 cd SimIt-ARM-3.0-gk ./configure make make install After these steps, the ./build/bindirectory contains the following programs: ema An ARM interpreter. To test the installation was successful type ./build/bin/ema test/wc configure modifiy PATH environment variable: PATH=$PATH:$HOME/SimIt-ARM-3.0-gk/build/bin ; export PATH 2. how to use 2.1 run user-level ARM programs [root@ORA9 SimIt-ARM-3.0-gk]# cd gcc-asm [root@ORA9 gcc-asm]# more hello.c /* * hello.c * Tue Sep 8 10:13:40 CST 2015 */ int main() { printf("hello world\n"); __asm("mov r0,#2\n\t" "swi 0x1\n\t"); // syscall: exit(2); } [root@ORA9 gcc-asm]# arm-linux-gcc -v Reading specs from /usr/local/arm/3.4.1/bin/../lib/gcc/arm-linux/3.4.1/specs Configured with: /opt/crosstool/crosstool-0.28/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-linux/gcc-3.4.1-glibc-2.3.2 --with-float=soft --with-headers=/opt/crosstool/arm-linux/gcc-3.4.1-glibc-2.3.2/arm-linux/include --with-local-prefix=/opt/crosstool/arm-linux/gcc-3.4.1-glibc-2.3.2/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long Thread model: posix gcc version 3.4.1 [root@ORA9 gcc-asm]# arm-linux-gcc hello.c -o hello -static [root@ORA9 gcc-asm]# ls -l hello* -rwxr-xr-x 1 root root 520775 Sep 8 10:18 hello -rw-r--r-- 1 root root 160 Sep 8 10:15 hello.c [root@ORA9 gcc-asm]# file hello hello: ELF 32-bit LSB executable, ARM, vers

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fire丶Chicken

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值