因此,我试图将两个BigIntegers 22和7分开。换句话说,我试图将b1.divide(b2)[where b1 = new BigInteger("22")和b2 = new BigInteger("7")]的前十进制存储到某种数据类型中。但是,如果使用a BigDecimal,它将显示一个无法表示的数字错误,而它甚至不能用于双打。我该怎么办?为了您的方便,以下是代码:
BigInteger b1 = new BigInteger("22");
BigInteger b2 = new BigInteger("7");
BigInteger b3 = b1.divide(b2);
System.out.println(b3);
Run Code Online (Sandbox Code Playgroud)
这就是控制台中显示的内容:
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decima
l expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(Unknown Source)
at Divider.main(Divider.java:13)
Run Code Online (Sandbox Code Playgroud) 我在 WSL Ubuntu 上使用 g++。我使用 git 克隆了 GLFW 存储库,使用ccmake命令来配置和生成二进制文件,然后make在“build”目录中使用以最终创建文件.a。我安装了所有与 OpenGL 相关的库/usr/ld(我不记得到底安装了哪些库,因为我必须安装这么多。无论如何,g++ 命令有效,所以我认为它是成功的)。后来我在VS Code上做了一个项目,如下所示:
GLFW 包含文件夹来自上述克隆的存储库,GLAD 和 KHR 包含文件夹来自glad.dav1d.de,我将 GL 版本(在 API 下)设置为3.3,将 Profile 设置为Core。
在 中main.cpp,我放置了一段用于初始化 GLFW 的简单代码片段:
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main()
{
// Initialize GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return 1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
std::cout << "Success" << …Run Code Online (Sandbox Code Playgroud)