我正在试验各种编程语言中双精度值的精度。
#include <stdio.h>
int main() {
for (double i = 0.0; i < 3; i = i + 0.1) {
printf("%.17lf\n", i);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
#include <iostream>
using namespace std;
int main() {
cout.precision(17);
for (double i = 0.0; i < 3; i = i + 0.1) {
cout << fixed << i << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
i = 0.0
while i < 3:
print(i)
i = i + 0.1
Run Code Online (Sandbox Code Playgroud)
public class …Run Code Online (Sandbox Code Playgroud) 我在 VScode 上使用了调试工具(ctrl + shift + D)和自定义的 launch.json,但我无法运行我的程序。帮我解决这个问题。 这是我的回溯
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
run()
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "/usr/lib/python3.6/runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "/usr/lib/python3.6/runpy.py", line 236, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "/home/odroid/Documents/python/crawling-worker/.vscode/launch.json", line 2
// Use …Run Code Online (Sandbox Code Playgroud) python debugging remote-debugging web-crawler visual-studio-code
我正在尝试使用光线行进渲染球体网格。SDF 函数如下所示:
float sq_layer(vec3 p, vec3 bounding_box_min, vec3 bounding_box_max)
{
float cell_size = 4.0 / 16.0;
vec3 p0 = clamp(p.xyz, bounding_box_min, bounding_box_max);
p0 = mod(p0, cell_size) - cell_size * 0.5f;
float d_pt = sphereSDF(vec3(p0.x, p0.y, p0.z), 0.05f)
return d_pt;
}
Run Code Online (Sandbox Code Playgroud)
为了获得更多相关性,我尝试稍微更改一下代码:
float sq_layer(vec3 p, vec3 bounding_box_min, vec3 bounding_box_max)
{
vec3 cell_size = (bounding_box_max - bounding_box_min) / 4.0;
vec3 p0 = clamp(p.xyz, bounding_box_min, bounding_box_max);
p0 = mod(p0, cell_size) - cell_size * 0.5f;
float d_pt = boxSDF(p0, cell_size * 0.35);
return …Run Code Online (Sandbox Code Playgroud) 我在下面的代码中的最后一个 elif 和 else 语句有一个相当简单的问题......它们根本不会执行。我是 python 的大菜鸟,所以很可能是一个简单的错误:/控制台不显示任何语法错误或任何东西......它执行代码,但结果错误
starthandvalue = 0
if splitfirstcard[0] == splitsecondcard[0]:
ispar = True
if (splitfirstcard[0] and splitsecondcard[0] == 'A') or (splitfirstcard[0] and splitsecondcard[0]== 'K') or (splitfirstcard[0] and splitsecondcard[0] == 'Q'):
starthandvalue =+83
elif (splitfirstcard[0] and splitsecondcard[0] == 'J') or (splitfirstcard[0] and splitsecondcard[0] == '10') or (splitfirstcard[0] and splitsecondcard[0] == '9'):
starthandvalue =+75
elif (splitfirstcard[0] and splitsecondcard[0] == '8') or (splitfirstcard[0] and splitsecondcard[0] == '7') or (splitfirstcard[0] and splitsecondcard[0] == '6') or (splitfirstcard[0] and splitsecondcard[0] == '5'): …Run Code Online (Sandbox Code Playgroud) 所以,我对 C 完全陌生。我正在测试这些语言的性能。
我做了什么?
我用 C 编写了两个程序,一个是用 Java 编写的,它们都做同样的事情,但是与 Java 相比,C 非常慢?
以下是程序:
主文件:
#include <stdio.h>
#include <time.h>
#include <conio.h>
void work();
int main() {
time_t seconds;
seconds = time(NULL);
printf("time1 : %ld\n", seconds);
work();
seconds = time(NULL);
printf("time2 : %ld\n", seconds);
return 0;
}
void work() {
int a[1000][500];
for (int k = 0; k < 10000; ++k) {
for (int i = 0; i < 1000; ++i) {
for (int j = 0; j < 500; ++j) …Run Code Online (Sandbox Code Playgroud) python ×3
c ×2
java ×2
c++ ×1
debugging ×1
gcc ×1
glsl ×1
opengl ×1
performance ×1
precision ×1
raymarching ×1
web-crawler ×1