SELECT YEAR, period, round((1- sum(rej_qty) / sum(recd_qty))*100, 0)
FROM TAB_A
WHERE sid = '200'
AND sdid IN ('4750')
AND
(
(
YEAR ='2011'
AND period IN('01_JAN')
)
OR
(
YEAR = '2010'
AND period IN('02_FEB','03_MAR','04_APR','05_MAY','06_JUN','07_JUL','08_AUG','09_SEP','10_OCT','11_NOV','12_DEC')
)
)
group by year, period
Run Code Online (Sandbox Code Playgroud)
对于特定月份,recd_qty为零,因为我得到了DIVIDE BY ZERO错误.
有什么方法可以避免DIVIDE BY ZERO错误吗?
我有什么方法可以忽略那个特定的月份?
I came across this answer on Programming Puzzles & Code Golf. In it, the author uses the expression (though the answer has since been edited to use a different solution):
row_number()over(order by 1/0)
Run Code Online (Sandbox Code Playgroud)
I would have expected the 1/0 to result in a divide by zero exception, but it doesn't.
When I asked the author on PPCG, they replied "because 1/0 is not being calculated. where exists(select 1/0) will have the same effect". This leaves me a bit nonplussed, because …
我正在努力获得一种可靠的方法来捕获Visual Studio(2005或2008)下的浮点异常.默认情况下,在visual studio下,浮点异常没有被捕获,并且它们很难捕获(主要是因为它们中的大多数是硬件信号,需要转换为异常)
这是我做的:
- 打开SEH异常处理
(属性/代码生成/启用C++异常:是的SEH异常)
- 使用_controlfp激活浮点异常
我现在抓住异常(如下面的例子中所示,简单的除零除外).但是,一旦我捕获到这个异常,似乎程序被无可挽回地破坏了(因为简单的float初始化,以及std :: cout将不起作用!).
我已经构建了一个简单的演示程序,显示了这种相当奇怪的行为.
注意:此行为已在多台计算机上重现.
#include "stdafx.h"
#include <math.h>
#include <float.h>
#include <iostream>
using namespace std;
//cf http://www.fortran-2000.com/ArnaudRecipes/CompilerTricks.html#x86_FP
//cf also the "Numerical Recipes" book, which gives the same advice
//on how to activate fp exceptions
void TurnOnFloatingExceptions()
{
unsigned int cw;
// Note : same result with controlfp
cw = _control87(0,0) & MCW_EM;
cw &= ~(_EM_INVALID|_EM_ZERODIVIDE|_EM_OVERFLOW);
_control87(cw,MCW_EM);
}
//Simple check to ensure that floating points math are still working
void CheckFloats() …Run Code Online (Sandbox Code Playgroud) 我的应用程序是用Delphi5编写的.我正在使用madExcept来追踪错误.我追踪了一个"浮点dvision by zero"异常,它不应该是.引发它的代码段如下:
val:=100*Power(1.25,c);
Run Code Online (Sandbox Code Playgroud)
其中'c'实际上总是具有值'1'.
日志的堆栈跟踪:
main thread ($338f8):
00403504 +010 MyApp.exe System 1970 +5 @FRAC
00479148 +058 MyApp.exe Math Power
007ae8a6 +262 MyApp.exe MyClass 1962 +36 TMyClass.FormMouseWheel
Run Code Online (Sandbox Code Playgroud)
我有一个例外,一个分区确实发生了,但是除数是一个变量,当异常发生时它也有一个值'1'.我能够调试和重现.
我的问题:我错过了什么?浮点除法是否有一些我不知道的误报?
此外:我没有在异常点使用任何C++ DLL,因为它们倾向于以不同方式处理FP分区(返回NaN或+/- INF而不是引发异常).
任何指针赞赏.
我对ARM处理器的内部细节不是很熟悉,但是我不了解Nvidia Jetson Nano开发板上的以下行为。
C代码示例...
//main.c
#include <stdio.h>
int main()
{
int fred = 123;
int i;
for(i = -10 ; i <= 10 ; i++)
printf("%d / %d == %d\n", fred, i, fred / i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译:
gcc main.c -ggdb
Run Code Online (Sandbox Code Playgroud)
运行生成的a.out可执行文件将产生以下输出...
123 / -10 == -12
123 / -9 == -13
123 / -8 == -15
123 / -7 == -17
123 / -6 == -20
123 / -5 == -24
123 / -4 == -30
123 / …Run Code Online (Sandbox Code Playgroud) 我试图理解下面的代码res1之间的区别:res2
#include <iostream>
int main()
{
int x = 1;
int y = 0;
double res1 = double(x)/y; // OK: evaluates to Inf
int res2 = x/y; // run-time error: Floating point exception
// 1/0; // g++ warning: division by zero [-Wdivision-by-zero]
std::cout << res1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
据我了解,除以零是 C++ 标准中未定义的行为,并且res1和之间存在差异的原因res2是由于我的机器为 实现了 IEEE 754 double,它需要除以零才能返回Inf或-Inf。
但现在我想知道为什么标准必须首先对除以零做出任何声明。这个答案说它是为了适应实现 C++ 的各种不同的体系结构,但我不确定 -除以零不是更多的运行时问题吗?特别是如果编译器在大多数情况下不太可能在不评估分母的情况下检测到它(我认为这就是上面示例中发生的情况)。当然,如果我尝试类似 的操作 …
我们在Sun JRE 1.6中遇到了KeyManagerFactory的问题.我们使用类似以下的代码上传和使用p12格式的证书:
KeyStore keyStore = KeyStore.getInstance(PKCS12);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(SUN_X509);
InputStream certificateFile = getSSLCertificate();
String certificatePassword = getSSLCertificatePassword();
keyStore.load(certificateFile, certificatePassword);
keyManagerFactory.init(keyStore, certificatePassword);
Run Code Online (Sandbox Code Playgroud)
当证书密码存在时,此代码可正常工作.但是当证书密码为空(因此证书不受密码保护)时,我们会从keyManagerFactory.init行获得除以零错误.
有谁知道为什么会这样?没有密码就不能使用证书吗?谢谢
在进行报告时,最佳方式(对用户最直观)或显示除以0错误结果的最佳实践是什么?在报告中,我在人类可读报告中显示时会捕获此错误; 我不知道该怎么说.
一个例子就是体重/收入比.对于给定的终端,在给定的一天,可能没有收入,但是一些货物(可能具有重量)可能已经被运送.
我正在查看当前的报告,通过在列中放置0来处理此问题,但是,这可能会产生误导,因为这在技术上并不正确.
另一个想法是把它留空; 但是,用户不知道该字段为空的原因.
我也考虑过标准的Excel错误,#DIV/0!但这往往会使报告看起来很混乱.
我很好奇其他人过去为这种情况所做的事情.
#include<stdio.h>
void function(int);
int main()
{
int x;
printf("Enter x:");
scanf("%d", &x);
function(x);
return 0;
}
void function(int x)
{
float fx;
fx=10/x;
if(10 is divided by zero)// I dont know what to put here please help
printf("division by zero is not allowed");
else
printf("f(x) is: %.5f",fx);
}
Run Code Online (Sandbox Code Playgroud) 由于减法中的浮点误差,在以下情况下是否可以除零?
float x, y, z;
...
if (y != 1.0)
z = x / (y - 1.0);
Run Code Online (Sandbox Code Playgroud)
换句话说,以下是否更安全?
float divisor = y - 1.0;
if (divisor != 0.0)
z = x / divisor;
Run Code Online (Sandbox Code Playgroud) c++ floating-point floating-accuracy divide-by-zero floating-point-precision