[英]test-js: scientific software: significant figures
I am attempting to test scientific software written in TypeScript using Jest.我正在尝试使用 Jest 测试用 TypeScript 编写的科学软件。
I want to test all my floating point results to 8 significant figures, but it seems the only test method available in ts-jest, "toBeCloseTo", works on matching figures after the decimal point in decimal notation.我想将所有浮点结果测试为 8 位有效数字,但似乎 ts-jest 中唯一可用的测试方法“toBeCloseTo”适用于十进制小数点后的匹配数字。
https://jestjs.io/docs/en/expect#tobeclosetonumber-numdigitshttps://jestjs.io/docs/en/expect#tobeclosetonumber-numdigits
The scientific and engineering community works to significant figures, rather than numbers after the decimal point.科学和工程界致力于有效数字,而不是小数点后的数字。 Have I overlooked some functionality.我是否忽略了一些功能。 If not, is there a plan to add it?如果没有,是否有计划添加它?
In the meantime, I have a workaround which would only work for numbers where the significant figures after the decimal point in decimal notation are within the range of the significant figures required in scientific notation.同时,我有一个解决方法,它只适用于十进制小数点后的有效数字在科学记数法要求的有效数字范围内的数字。
test("MyFunction", () =>{
let sigAfterDecimal = SIG_FIG - Math.floor((Math.log(ExpectedResult)/Math.log(10)));
expect(IF97_B23T(functionInput)).toBeCloseTo(SigAfterDecimal, thisTestAccuracy);
});
But this wouldn't work for checking eg.但这不适用于检查例如。 the Avogadro constant, 6.02214076×10^23 to 8 significant figures, as none of the relevant significant figures appear after the decimal point in decimal notation.阿伏伽德罗常数,6.02214076×10^23 到 8 位有效数字,因为在十进制表示法中小数点后没有相关有效数字出现。
Well, I've had a go myself and have created a pull request to the main facebook/jest team to include my fork "float_sig_fig" which adds toBeCloseToSigFig which that the powers in normalized scientific notation are the same and that the mantissas match to a required number of significant figures.好吧,我自己有一个 go 并向主要的 facebook/jest 团队创建了一个拉取请求,以包括我的叉子“float_sig_fig”,它添加到 BeCloseToSigFig 中,标准化科学记数法中的权力是相同的,并且尾数匹配所需的有效数字数。 Thanks to Chux I made sure the log(0) case is covered.感谢 Chux,我确保涵盖了 log(0) 案例。
It would be my first source contribution to an open source software project if it is accepted.如果它被接受,这将是我对开源软件项目的第一个源代码贡献。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.