Skip to content.

kagome.lab.tkikuchi.net

Sections
Personal tools
You are here: Home » Members » tkikuchi's Home » 授業 » 専門コア情報処理演習(2006) » 解答例7
Views

解答例7

Document Actions
  1. >>> 1 + 2 * 3
    7
    >>> ( 1 + 2 ) * 3
    9
    >>> 10 / 0
    Traceback (most recent call last):
      File "", line 1, in ?
    ZeroDivisionError: integer division or modulo by zero
    >>> 1. + 2 * 3
    7.0
    >>> ( 1. + 2 ) * 3
    9.0
    >>> 10 / 0.
    Traceback (most recent call last):
      File "", line 1, in ?
    ZeroDivisionError: float division
    >>>
    
    • ゼロで割ったときのエラーは整数と浮動少数で微妙に違うことにも注意
  2. >>> from math import *
    >>> sin(1e-6)/1e-6
    0.99999999999983336
    >>> sin(1e-7)/1e-7
    0.99999999999999833
    >>> sin(1e-8)/1e-8
    1.0
    >>>
    
  3. >>> 1e307
    9.9999999999999999e+306
    >>> 1e308
    1e+308
    >>> 1e309
    inf
    >>> 10**10000
    100000000000000...
    ...
    0L
    >>>
    
    • ちなみに

      >>> 1e-323
      9.8813129168249309e-324
      >>> 1e-324
      0.0
      

  4. >>> (1 + 2j)/(3 + 4j)
    (0.44+0.080000000000000002j)
    >>> x = 3**2 + 4**2
    >>> (1*3+2*4)/x
    0
    >>> (1.*3+2*4)/x
    0.44
    >>> (2.*3-1.*4)/x
    0.080000000000000002
    >>>
    
Created by tkikuchi
Last modified 2006-11-26 15:39
 

Powered by Plone

This site conforms to the following standards: