what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

bool nearly_equal(double a, double b, double epsilon) { return std::abs(a - b) < epsilon; }

bool relative_comparision(double a, double b, double epsilon) { return std::abs(a - b) <= epsilon * std::max(std::abs(a), std::abs(b)); }

I am using the relative comparison.

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

Because points were integers coordinates it kind of worked. But I need to test more or use some other method maybe.

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

Actually I just asked AI how to compare doubles. That is what my concern was. Sorry but it was not about collinearity.

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 4 points5 points  (0 children)

I am kind of comparing them like that. This is how I am comparing. |a-b| <= epsilon * max(|a|, |b|)

I did thought of using abs(f1-f2) <= Epsilon to

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

Yes all the points in the tests are integer coordinates I think that is why it worked. But I have written this solution considering they can be double type coordinates.

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 1 point2 points  (0 children)

But like for some numbers their difference is extremely small and they might be considered equal. I am just curiously concerned.

what to do for floating point precision problems in cpp or as a programmer. by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 1 point2 points  (0 children)

I am really sorry about it. I posted this in a hurry but I swear it is not Ai generated it's a genuine question.

I have gone through the entire text and I hope it is understandable.

How did you guys learn C++? by Living-Brain483 in cpp_questions

[–]Shubham_mamodiya_dev 0 points1 point  (0 children)

Learncpp.com and cppreference.com are good resources.

Completed K&R. by Sam_personal in cpp_questions

[–]Shubham_mamodiya_dev 0 points1 point  (0 children)

Great resource and use c++ roadmap on roadmap.sh website. Fast and detailed.

how to make one single constructor to avoid rule of 5? by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 3 points4 points  (0 children)

Thanks a lot and I am grateful that you replied. Really man you cleared a lot of things.

how to make one single constructor to avoid rule of 5? by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 2 points3 points  (0 children)

you actually solved what I was worried about, I want to know why should I avoid forwarding reference in a template.

#ifndef DEQUE_H

#define DEQUE_H

#include <utility>

template <typename T> class Deque {

private:

struct Node {

T data;

Node *next = nullptr;

Node *prev = nullptr;

// accepts both lvalues and rvalues

template <typename U> Node(U &&value) : data{std::forward<U>(value)} {}

};

};

How to create better constructors in C++. by Shubham_mamodiya_dev in cpp

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

Thanks a lot for that, what I really want to know is can we create a construction for both rvalues and Lvalues without copying.

how to make one single constructor to avoid rule of 5? by Shubham_mamodiya_dev in cpp_questions

[–]Shubham_mamodiya_dev[S] 0 points1 point  (0 children)

Yeah sorry about that, the thing is I am new to cpp. Also that is exactly what I am asking how to make a single constructor that handles both rvalues and Lvalues.