小编13l*_*H4t的帖子

MIPS如何计算大于1.111 x2 ^ 1023的数字?

我正在使用MIPS和MARS 4.5.有没有办法计算扩展范围1.111 ..*2 ^ 1023的数字?

例如(factorial func):

.data
     dval:    .double   171.0  # its working up to 170!
     one:     .double   1.0  

.text
     l.d      $f2, dval
     l.d      $f4, one
     l.d      $f12, one
lo:  c.eq.d   $f2, $f4          # calc factorial of 171 = Infinity 
     bc1t     ex
     mul.d    $f12, $f12, $f2
     sub.d    $f2, $f2, $f4
     j        lo
ex:  li       $v0, 3
     syscall
Run Code Online (Sandbox Code Playgroud)

如何计算和打印171的阶乘?

floating-point double assembly mips factorial

1
推荐指数
1
解决办法
95
查看次数

Python-sys.stdout.flush()在python 2.7中的2行

我正在用python 2.7编写

我有以下代码:

a = 0
b = 0
while True:
    a += 1
    b += 1
    print str(a)
    print str(b)
Run Code Online (Sandbox Code Playgroud)

输出如下:

1
1
2
2
3
3
4
....
Run Code Online (Sandbox Code Playgroud)

并希望用这两行冲洗stdout.flush().代码看起来像这样,但它不起作用..

import sys

a = 0
b = 0
while True:
    a += 1
    b += 1
    sys.stdout.write(str(a)+"\n")
    sys.stdout.write(str(b)+"\r")
    sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)

这会产生如下输出:

1   #1
2   #1   ->#2
3          #2   ->#3
4                 #3   ->#4
...
Run Code Online (Sandbox Code Playgroud)

我知道这是因为\r只跳到第二行的开头,然后从下一个打印开始..

如何将光标设置为第1行的开头而不是第2行?

所以它只刷新2行:

n  #1 ->#2  ->#3  ->#4  ->#.....
n  #1 ->#2  ->#3 …
Run Code Online (Sandbox Code Playgroud)

python stdout flush sys python-2.7

0
推荐指数
1
解决办法
1666
查看次数

标签 统计

assembly ×1

double ×1

factorial ×1

floating-point ×1

flush ×1

mips ×1

python ×1

python-2.7 ×1

stdout ×1

sys ×1