检查双精度是否为奇数 [英] check if a double is odd or not

查看:64
本文介绍了检查双精度是否为奇数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



检查双数是否为奇数的快速方法?谢谢


any quick way to check if a double is an odd number or not? thanks

推荐答案

Angelo Chen说:
Angelo Chen said:

hi,

任何快速检查双数是否为奇数的方法?谢谢

any quick way to check if a double is an odd number or not? thanks



首先,请告诉我3.1415926是否为奇数。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

First, please tell me whether 3.1415926 is an odd number.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


6月18日下午12:19,Angelo Chen< angelochen ... @ gmail.comwrote:
On Jun 18, 12:19 pm, Angelo Chen <angelochen...@gmail.comwrote:



任何快速检查双数是否为奇数的方法?谢谢

any quick way to check if a double is an odd number or not? thanks



双和奇有什么关系?简单测试是计算mod 2:

unsigned int n = NUM​​;

if(1 ==(n%2)){

/ * odd * /

}


如何为小数定义奇数? 2.1是奇数还是偶数?通过加倍,如果

你只是意味着有更大的尺寸而不是小数值,那么你

可以将结果转换为int。

double num = NUM​​;

if(1 ==(int)(num%2)){

/ * odd * /

}

What''s with double and odd? The simples test is to calculate mod 2:
unsigned int n = NUM;
if ( 1 == (n % 2)) {
/* odd */
}

How do you define odd for decimals? 2.1 is odd or even? By double, if
you just mean to have larger size and not the decimal values, then you
can cast the result to int.
double num = NUM;
if ( 1 == (int)(num % 2)){
/* odd */
}





你是对的,我有这个需要双倍包含时间

自2001年1月1日起以秒为单位的间隔,所以双人将不会有一个

小数部分,这是我现在使用的,但不确定是否这个

适用于所有情况:


double t; // t是设置在某个地方的时间间隔


double d = t / 2.0;

if(floor(d)* 2.0!= t){< br $>
//奇数

}


6月18日下午3:46 *,Richard Heathfield< r ... @ see.sig.invalidwrote:
Hi,

you are correct, I have this need that the double contains a time
interval in seconds since jan, 1, 2001, so the double will not have a
fractional part, here is what I use now, but not so sure if this
applies to all situation:

double t; // t is a time interval set somewhere

double d = t / 2.0;
if (floor(d)*2.0 != t) {
// odd number
}

On Jun 18, 3:46*pm, Richard Heathfield <r...@see.sig.invalidwrote:

Angelo Chen说:
Angelo Chen said:

hi,

任何快速检查双数是否为奇数的方法?谢谢

any quick way to check if a double is an odd number or not? thanks



首先,请告诉我3.1415926是否为奇数。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - 1999年7月29日dmr


First, please tell me whether 3.1415926 is an odd number.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于检查双精度是否为奇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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