C语言编写程序输出三角形二元一次方程组求解程序时输出“x=-1.#QNAN0 y=-1.#QNAN0”,检验后double的范围也没超。

nan - How to test for -1.#IND (indeterminate) in Lua? - Stack Overflow
Stack Overflow for Teams
A private, secure home for your team's questions and answers.
to customize your list.
This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our , , and our .
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
Irrelavent justification for the question:
i'm getting an error calling Lua format:
integer overflow attempting to store -1.#IND
The variable's type(n) really is a number, and i can format it as a string (i.e. %s), but it's not a number, e.g.:
print(string.format("value=%s, type=%s", n, type(n)));
for the NaN value returns:
value=-1.#IND, type=number
i want to fix this, but i have no idea who is generating this NaN (Lua has no debugger).
So i'm left with having to throw a lot of asserts all over the code until i can pin down to the source of this intermittent NaN value.
But i can't find any condition that traps it, and Lua doesn't have isnan(x).
How can i test a number for -1.#IND in Lua?
if (n ~= n) then
print(string.format("NaN: value=%s, type=%s", n, type(n)));
print(string.format("value=%s, type=%s", n, type(n)));
and it prints
value=-1.#IND, number
Update Two: Just in case i missed something, my actual code is:
if (oldValue ~= oldValue) then
print(string.format("Is NaN: labelNumber=%d, formatString=\"%s\", oldValue=%s (%s)", labelNumber or 0, formatString or "nil", oldValue or "nil", type(oldValue)));
print(string.format("Is not NaN: labelNumber=%d, formatString=\"%s\", oldValue=%s (%s)", labelNumber or 0, formatString or "nil", oldValue or "nil", type(oldValue)));
And the faulty value outputs:
Is not NaN: labelNumber=4, formatString="%d", oldValue=-1.#IND (number)
Update Three
Still trying to solve this problem, i just noticed the absurdadity of reality:
function isnan(x)
if type(x) ~= "number" then
--only a number can not be a number
110k180650977
n ~= n may work (with the caveats described in Mud's answer), but a more portable one may be:
function isnan(n) return tostring(n) == tostring(0/0) end
Those who are concerned about division by zero (as in Ian' although I haven't seen it in practice) can use an alternative version:
function isnan(n) return tostring(n) == tostring((-1)^.5) end
Full function:
--local nanString = (tostring((-1) ^ 0.5)); --sqrt(-1) is also NaN.
--Unfortunately,
tostring((-1)^0.5))
= "-1.#IND"
x = tostring((-1)^0.5))
--With this bug in LUA we can't use this optimization
local function isnan(x)
if (x ~= x) then
--print(string.format("NaN: %s ~= %s", x, x));
--only NaNs will have the property of not being equal to themselves
--but not all NaN's will have the property of not being equal to themselves
--only a number can not be a number
if type(x) ~= "number" then
--fails in cultures other than en-US, and sometimes fails in enUS depending on the compiler
if tostring(x) == "-1.#IND" then
--Slower, but works around the three above bugs in LUA
if tostring(x) == tostring((-1)^0.5) then
--print("NaN: x = sqrt(-1)");
--i really can't help you anymore.
--You're just going to have to live with the exception
110k180650977
18.2k22435
Lua doesn't have isnan(x).
You can add one to your Lua host or create a module with that function. Just a few lines of code.
How can i test a number for -1.#IND in Lua?
Well, you know that it's converting NaN in to the string representation '-1.#IND', so you could write:
function isnan(n) return tostring(n) == '-1.#IND' end
Or, , this will work:
function isnan(n) return n ~= n end
20.8k64067
For serializing purposes, this seems to work best for me:
local function isnan(val)
if val==1/0 then return "1/0"
elseif val==-1/0 then return "-1/0"
elseif val~=val then return "0/0"
This lets me:
print(v .. " = " .. isnan(val) or val)
The result is then, for example,
foo = 1/0,
bar = 0/0,
bla = -1/0,
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By clicking &Post Your Answer&, you acknowledge that you have read our updated ,
and , and that your continued use of the website is subject to these policies.
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled设计一个求二元一次方程组的解的c程序_百度知道
设计一个求二元一次方程组的解的c程序
您的回答被采纳后将获得:
系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
我有更好的答案
二元一次方程组的解的c程序关注这个问题!
为您推荐:
其他类似问题
二元一次方程组的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。C++编程时算出来的得数1.#QNAN是什么意思?怎么解决?送100分_百度知道
C++编程时算出来的得数1.#QNAN是什么意思?怎么解决?送100分
我有更好的答案
这一般说明你的数字超过了float的表示范围,比如用一个很大的数除很小的数,或者除0错误,你应该查你的程序里边是否有这方面的错误,一般是这样写的“-1#NAN”NAN=Not A Number
采纳率:64%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。怎么用c语言编一个程序解二元一次方程【编程吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:220,212贴子:
怎么用c语言编一个程序解二元一次方程收藏
啊啊啊 谢谢恩
编程,博为峰IT培训免费试听,0元入学,现在更有多重优惠,仅限今天!博为峰,真正的为年轻人服务的企业,14年间培训15万余名it工程师,成绩斐然!
人!工!置!顶!
可以把function(x)*function(y)&0作为判断条件进行循环。。。
我给弟弟写过一个,还有解题步骤的
这不是有公式吗,直接用公式
x1=(-b+sqr(b^2-4ac))/2ax2=(-b-sqr(b^2-4ac))/2a
直接求根公式啊~~~~~~~~
潜水出来冒泡
怎么用c语言编一个中考作弊的程序啊!!??体育也要
登录百度帐号当前位置:
C语言求解三元一次方程组的解
C语言求解三元一次方程组的解
来源:网络整理&&&&&时间: 21:04:48&&&&&关键词:
关于网友提出的“ C语言求解三元一次方程组的解”问题疑问,本网通过在网上对“ C语言求解三元一次方程组的解”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: C语言求解三元一次方程组的解
课程设计题目:求三元一次方程组的解。
内容:输入任一三元一次方程组,并保存到data.dat文件中,判断该方程组有无解,如有解,判断是唯一解还是无穷解,输出所求方程解。若无穷解,解中可包含不多于2个变量并解输出到data.dat文件。要求采用模块化程序设计方法,在程序界面,以菜单的形式调用各功能函数;
课程结束后上交说明书,内容程序设计题目需求分析(分析题目要求)程序框图‘总体框图和功能模图’核心技术的实现及其程序段总结
我是半路出家做java的,现在上学的弟弟课程设计,教我帮忙,请c的高手,抽出宝贵的时间给弄弄。解决方案1:
|||||||||||||||||||||||||||||||||||||
|||&a1x+b1y+c1z=d1
|||&a2x+b2y+c2z=d2
|||&a3x+b3y+c3z=d3
|||||||||||||||||||||||||||||||||||||
一&&a1a2x+b1a2y+c1a2y=d1a2&&A式
&&&&a1a2x+b2a1y+c2a1z=d2a1&&B式
&&&&&(b1a2-b2a1)y+(c1a2-c2a1)z=(d1a2-d2a1)&&&C式
&&&&如果b1a2-b2a1=0或c1a2-c2a1=0则存在无穷多组解
二&&a3a2x+b3a2y+c3a2y=d3a2&&D式
&&&&a3a2x+b2a3y+c2a3z=d2a3&&E式
&&&&&(b3a2-b2a3)y+(c3a2-c2a3)z=(d3a2-d2a3)&&&F式
&&&&如果b3a2-b2a3=0或c3a2-c2a3=0则存在无穷多组解
求&C和F式组成的二元一次方程组
接着。。。。。。。。。。难道你还想不出来吗&呵呵
解决方案2:
你用java&写吧,
基本差别不大&......
用简单一些的语句就成&..
然后在改装一下&...
以上介绍了“ C语言求解三元一次方程组的解”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3129666.html
上一篇: 下一篇:

我要回帖

更多关于 编写程序输出杨辉三角 的文章

 

随机推荐