漂浮为无限 [英] Float as Infinity

查看:57
本文介绍了漂浮为无限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有


我有浮动问题

我应该写一个程序,你可以从
$获得一些数字b $ b命令行并尝试查找这些

数字的最大值和最小值。

我需要初始化2个浮点数(一个带负无穷大,一个带有

加无穷大),或者其他人有什么想法吗?


到目前为止我已经制作了这段代码:

#include < stdio.h>


int main(void){

int sat = 0;

float max = 0.0, x;

float min = plus-infinity;

printf(写一些数字:\ n);


while(scanf("%f",& x)== 1){


if(max< x){

max = x ;

}


if(sat == 0){

min = x;

sat = 1;

}否则{

if(min> x){

min = x;

}

}

}


printf("%f is max \ n",max);

printf("%f is min \ nn,min);

返回0;

}

Hey all

I have a problem with float
I should write a program, where you are getting some numbers from the
command-line and try to find the maximum and minimum-values of these
numbers.
I need to initialize 2 floats (one with minus infinity and one with
plus infinity), or does anybody else have an idea?

I have made this code until now:
#include <stdio.h>

int main(void) {
int sat = 0;
float max = 0.0, x;
float min = plus-infinity;
printf ("Write some numbers:\n");

while( scanf("%f", &x) == 1) {

if (max<x) {
max=x;
}

if (sat == 0) {
min = x;
sat = 1;
} else {
if (min>x) {
min = x;
}
}
}

printf ("%f is max\n", max);
printf ("%f is min\n", min);
return 0;
}

推荐答案

math.h中定义的宏INFINITY应该做(负无穷大是

只需-INFINITY)。它是在较新的ISO C99标准中引入的,因此

某些编译器可能没有它们或使用其他名称。

The macro INFINITY defined in math.h should do (negative infinity is
simply -INFINITY). It is introduced in the newer ISO C99 standard, so
certain compilers might not have them or use some other name.


9月24日13:15,r6144< rainy6 ... @ gmail.comwrote:
On 24 Sep., 13:15, r6144 <rainy6...@gmail.comwrote:

math.h中定义的宏INFINITY应该做(负无穷大)是

只需-INFINITY)。它是在较新的ISO C99标准中引入的,因此

某些编译器可能没有它们或使用其他名称。
The macro INFINITY defined in math.h should do (negative infinity is
simply -INFINITY). It is introduced in the newer ISO C99 standard, so
certain compilers might not have them or use some other name.



还有另一种方式,我可以做到吗?

Is there another way, I can do it then?


The87Boy写道:
The87Boy wrote:

9月24日,13:15,r6144< rainy6 ... @ gmail.comwrote:
On 24 Sep., 13:15, r6144 <rainy6...@gmail.comwrote:

> math.h中定义的宏INFINITY应该这样做(负无穷大就是-INFINITY)。它是在较新的ISO C99标准中引入的,因此某些编译器可能没有它们或使用其他名称。
>The macro INFINITY defined in math.h should do (negative infinity is
simply -INFINITY). It is introduced in the newer ISO C99 standard, so
certain compilers might not have them or use some other name.



还有另一种方式,我可以做到吗?


Is there another way, I can do it then?



做什么?如果你想要C90兼容性,

#include< float.h>

初始化为FLT_MIN或FLT_MAX

因为没有支持的方式处理无穷大。

Do what? If you want C90 compatibility,
#include <float.h>
initialize to FLT_MIN or FLT_MAX
as there is no supported way of handling infinities.


这篇关于漂浮为无限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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