小编Ati*_*ioA的帖子

如何设置浮点数的精度

有人可以解释一下如何用C函数选择浮点精度吗?

例子:

theFatFunction(0.666666666, 3) 返回0.667

theFatFunction(0.111111111, 3) 返回0.111

c floating-point precision

13
推荐指数
1
解决办法
6万
查看次数

将 map 与具有多个参数的函数一起使用

是否可以将 map 与带有多个参数的函数一起使用?

我想重复使用 map 的第二个和第三个参数作为函数的参数。如

mapF x y z = map (f y z) [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

因此,它会评估f与同yz的值,但x = 1x = 2x = 3等等。

haskell list partial-application higher-order-functions map-function

2
推荐指数
1
解决办法
4735
查看次数

Makefile可以编译所有.c文件而无需指定它们

我正在尝试创建一个Makefile,它.c可以编译所有文件而无需在Makefile中每行添加文件名行.我认为这与makefile非常相似- 一次编译所有c文件.这就是我想要做的事情:

1 - 验证是否所有.c文件都来自/src其各自的.o文件/obj.如果该.o文件不存在,请从该.c文件构建它;

2 - main.exe从所有编译.o并打开它/bin.

我的Makefile:

BIN     = ./bin
OBJ     = ./obj
INCLUDE = ./include
SRC     = ./src

all:
    gcc -c "$(SRC)/Distances.c" -o "$(OBJ)/Distances.o"
    gcc -c "$(SRC)/HandleArrays.c" -o "$(OBJ)/HandleArrays.o"
    gcc -c "$(SRC)/HandleFiles.c" -o "$(OBJ)/HandleFiles.o"
    gcc -c "$(SRC)/Classifier.c" -o "$(OBJ)/Classifier.o"
    gcc -c main.c -o "$(OBJ)/main.o"
    gcc -o $(BIN)/main.exe $(OBJ)/*.o -lm

run:
    $(BIN)/main.exe

clean:
    del /F …
Run Code Online (Sandbox Code Playgroud)

c makefile

0
推荐指数
2
解决办法
1286
查看次数

什么可能导致此睡眠排序实现中的未定义行为?

要了解C++中的线程,我做了这个睡眠排序实现.大多数时候,它工作正常.但是,也许每15个左右运行一次,我的睡眠排序函数返回的向量将包含一些垃圾值.有谁知道是什么原因引起的?

这是我输出的屏幕截图: 垃圾输出

这是我的代码:

#include <stdio.h>
#include <thread>
#include <chrono>
#include <vector>

std::vector<unsigned int> sleepSort(std::vector<unsigned int> toSort){
    //vector to hold created threads
    std::vector<std::thread> threadList;
    //vector to hold sorted integers
    std::vector<unsigned int> sorted;

    //create a thread for each integer, n, in "toSort" vector
    //each thread sleeps for n seconds then adds n to "sorted" vector
    for(int i = 0; i < toSort.size(); i++){
        threadList.push_back(
            std::thread(
              [](int duration, std::vector<unsigned int>& v){
                std::this_thread::sleep_for((std::chrono::seconds)duration);
                v.push_back(duration);
                }, toSort.at(i), std::ref(sorted)
              )
            );
    }

    //wait for each thread …
Run Code Online (Sandbox Code Playgroud)

c++ sorting multithreading c++11

-4
推荐指数
1
解决办法
64
查看次数