如果我把一个double转换为int会发生什么,但double的值超出范围? [英] What happens if I cast a double to an int, but the value of the double is out of range?

查看:1310
本文介绍了如果我把一个double转换为int会发生什么,但double的值超出范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将double转换为int,但是double的值超出范围,会发生什么情况?

What happens if I cast a double to an int, but the value of the double is out of range?

让我说这样做?

double d = double(INT_MIN) - 10000.0;
int a = (int)d;

a的值是多少?是否未定义?

What is the value of a? Is it undefined?

推荐答案

正确。从标准引用4.9,如果截断值不能在目标类型中表示,则行为未定义。

Precisely. Quoting from the Standard, 4.9, "The behavior is undefined if the truncated value cannot be represented in the destination type."

这篇关于如果我把一个double转换为int会发生什么,但double的值超出范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆