Pygame:简单的余弦函数

时间:2013-12-16 23:19:36

标签: pygame cosine

我试图调用简单的余弦计算。这是我的代码:

import pygame
from pygame.locals import *
import math

pygame.init()
screen = pygame.display.set_mode((480, 480))
myfont = pygame.font.SysFont("monospace", 15)
angle = 90*(math.pi/180)

while True:

    adj = math.cos(angle)
    display = myfont.render("opposite side: " + str(adj), 1, (255, 255, 0))
    screen.blit(display, (100,40))
    pygame.display.flip()

    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            exit(0)

由于cos(90)* 5 = 0,我希望代码显示该值。相反,我收到以下内容:

6.12323399574e-17

1 个答案:

答案 0 :(得分:0)

这将发生在floating point arithmetic。您应该在将值显示给用户之前截断该值。