• So both of these stories involve floating point values, but only in this case am I actually allocating memory.

    所以这两个故事都涉及到浮点类型,但是只有那样我们才能真正地分配到内存。

    哈佛公开课 - 计算机科学课程节选

  • And as you might expect, I'm going to then try and see if I can convert that into a float.

    正如你希望的我要试着把他们转化为浮点数,等一等。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • C So here I'm declaring a variable called c, and I'm pretty much translating the formula from the slide using the characters on my keyboard to a floating point value.

    这里我声明了一个变量,然后我把那个幻灯片上的公式,用键盘上的字符翻译成了,浮点数值。

    哈佛公开课 - 计算机科学课程节选

  • Last time we checked the type and said if it is a float you're okay. If not, carry on.

    并且会告之是否是一个浮点数,如果不是继续循环。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • It just throws the decimal point away and that's because, again, these are ints and the answer intuitively should be a floating point value, but I need to be more specific.

    它直接把小数点后面的数值丢弃掉了,因为,凭直觉,那些整型数和结果应该是一个浮点数据,但是我需要一个更精确的数值。

    哈佛公开课 - 计算机科学课程节选

  • So what that means is the compiler is actually going to first "cast" so to speak 13 from whatever it is - to a float -- to a floating point value -- and then perform the division for us.

    所以这里的意思是编译器将,做“计算“,譬如13这样一个浮点数,-到另一个浮点数-,然后为我们处理除法。

    哈佛公开课 - 计算机科学课程节选

  • But if it is not, it's going to print out a message here saying, you screwed up, somewhat politely, and it's going to go back around. So it'll just cycle until I get something of the right type.

    但是输入不是浮点数的话,我这里就会显示一个消息说,你搞砸了,该稍微有点礼貌吧?,然后我们继续执行循环,一直到得到正确类型的输入。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I could generalize this pretty nicely. Imagine the same kind of idea where I want to simply say I want to take input of anything and try and see how to make sure I get the right kind of thing. I want to make it polymorphic.

    对吧,我试着输入浮点数,我能更好的一般化它,想象下类似的想法,我需要输入些什么,然后看看输入的是否正确,我想使他更多元化些。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • There's no decimal point; there's no point zero; there's no floating point value, it's just a hardcoded integer.

    这里没有小数点,这里没有;,这里没有浮点数值,它只是一个整型数字。

    哈佛公开课 - 计算机科学课程节选

  • Here I actually need to tell the computer, "Give me some bytes in ram in which to store a value, and that value's going to be a floating point value."

    这里我的确需要告诉计算机,“给我一些字节内存,来存储一个值,那个值将是,浮点型的数值“

    哈佛公开课 - 计算机科学课程节选

  • OK, says it says enter a float. I give it something that can be converted into a float, it says fine. I'm going to go back and run it again though. If I run it again, it says enter a float.

    好了,看到他说输入一个浮点数,我输入它可以转换为浮点数的值,那没问题,我回过来再运行一遍,如果我再运行一遍。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • 0 >> David: Yeah, so I very deliberately changed this 9 to a 9.0 so that my math would actually be floating point math involving real numbers and not just integers.

    >,大卫:是的,我故意地把9改成9,那样我的数学实际上就是浮点数的了,包括实数,不只是整数。

    哈佛公开课 - 计算机科学课程节选

  • And he quite correctly, because he's more senior than I am, more experienced than I am, said it's actually a good thing.

    你可以用加法来加浮点数,他很明显是正确的,因为他比我年长些,比我更有经验些。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Last thing to say is why would you want to have exceptions? Well, let's go back to that case of inputting a simple little floating point.

    最后要讲的是为什么有异常处理?,回到输入一个简单的小浮点数的例子,如果我期望主要是。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • You can run into issues of things like overflow, underflow, with floating point numbers and when you see a whole bunches of ones, it's particularly a good time to be suspicious.

    来看看哪儿会出问题,你可能会碰到浮点数中的溢出和下溢问题,当你碰到一系列这种问题后,可能就会适时的开始怀疑结果的正确性。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And in that case, in general lists, I need to figure out what's the access time.

    一些浮点数,一些字符串,一些数组内部的数组,各种各样。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Second thing to notice, is that little piece of pseudo code is telling me things about values.

    然后需要注意的是,这些伪代码告诉了一些关于值方面的事情,我需要一个浮点数。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • The reason I want to point this out to you is, if we go back up to the kinds of data objects we started with, floats, ints, strings, they actually behave the same way.

    我要为大家指出这一点的原因是,如果我们想一下以前讲过的,数据类型的种类,浮点数,整数,字符串,它们实际上有相同的行为方式。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And that then let's me get to, basically, base this code. Having done that, height I simply call base with get float, I call height with get float, and do the rest of the work.

    现在让我们看看这段代码,其实已经写好了,我简单的调用下,用来得到一个浮点数,再调用下,来得到另外一个浮点数,然后做剩下的工作就可以了。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Need to get the base in. Second thing I want to do, I need to get the height, so I'm going to input a value for the height, also as a float, a floating point.

    也就是输入底的值,第二件我想要做的,事情就是得到三角形的高,因此我会输入一个值作为三角形的高,同样也是一个浮点数。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • ReadFloat We'll look at it in a second. Let me sort of set the stage up for this -- suppose I want to input -- I'm sorry I want you as a user to input a floating point number.

    名字叫,我们来看一会,我先来设置下情景-,假设我想输入,抱歉,我希望你们作为用户来输入一个浮点数。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • When you think about an int or a float or a dictionary or a list, you knew that there were functions that operated on them.

    当你想到整型,浮点型,或者链表时,你知道可以用函数去处理他们,但是当你传递一个参数,例如链表。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Could be ints, could be floats, could be a combination of things, some ints, some floats, some lists, some strings, some lists of lists, whatever.

    但是我们知道数组内部的元素,可以是任何对象,可能是整数也可能是浮点数,也可能是对象的组合,一些整数。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I can't rely on the user. I want to make sure I get a float in it, so how do I do that?

    我想确保这儿我得到的是一个浮点数,我该怎么做呢?

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • If I wanted to get full, real division, I should make one of them a float.

    如果我想要得到真正的除法答案,我需要把他们之中的一个,变为浮点数类型。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And I can fix this just by changing one of those values to a floating point.

    所以我可以通过改变其中一个,整型数为浮点数。

    哈佛公开课 - 计算机科学课程节选

  • So a floating point value again is a number with a decimal point, so it depends.

    一个浮点型数据就是一个,带小数点的数。

    哈佛公开课 - 计算机科学课程节选

  • Then I'd be multiplying a float by 5, so that's a float times an int.

    然后我们把这个浮点数乘以,那是浮点数乘以整型数。

    哈佛公开课 - 计算机科学课程节选

  • - And then I divide by an int -- that's okay because so long as you have a float involved at some point early on, you're okay.

    然后我除以一个整型数-,那是可以的因为现在为止,我们在之前已经,引入了一个浮点数,你是对的。

    哈佛公开课 - 计算机科学课程节选

  • Now, this is not the nicest way to do it but it'll work. I can look at the type of the value of base and compare it to the type of an actual float and see, are they the same?

    这不是最好的办法但它确实有用,我可以得到底的值的类型然后,和一个真的浮点数的类型比比,看他们是不是一样?

    麻省理工公开课 - 计算机科学及编程导论课程节选

$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定