Language: C++

#include <iostream>
#include <iomanip>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>
#include <cfloat>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8  
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

/*******************************************************/

typedef double coordinate_t;

struct coordinate {
  coordinate_t x, y;
  bool operator<(const coordinate & another) const {
    return x != another.x ? x < another.x : y < another.y;
  }
};

struct line {
  coordinate_t a, b, c;
  coordinate p, q;
};

// is p in [l.x, r.x] * [l.y, r.y] ?
bool in_section(coordinate p, coordinate l, coordinate r) {
  coordinate_t lx, ly, rx, ry;
  lx = min(l.x, r.x);
  rx = max(l.x, r.x);
  ly = min(l.y, r.y);
  ry = max(l.y, r.y);
  if (lx <= p.x && p.x <= rx && ly <= p.y && p.y <= ry) return true;
  else return false;
}

// the intersections of 2 lines
coordinate cross_of_2_lines(line k, line l) {
  coordinate_t dn = l.a * k.b - k.a * l.b;
  if (dn == 0) return{ NAN, NAN };
  else {
    coordinate ret;
    ret.x = (l.b * k.c - k.b * l.c) / dn;
    ret.y = (k.a * l.c - l.a * k.c) / dn;
    if (in_section(ret, k.p, k.q) && in_section(ret, l.p, l.q)) return ret;
    else return{ NAN, NAN };
  }
}


// the intersections of n lines
vector<coordinate> crosses_of_lines(vector<line> lines) {
  int n = lines.size();
  set<coordinate> st;
  Loop(i, n) {
    Loop(j, i) {
      coordinate p = cross_of_2_lines(lines[i], lines[j]);
      if (!_isnan(p.x )&& !_isnan(p.y)) st.insert(p);
    }
  }
  vector<coordinate> ret;
  for (auto itr = st.begin(); itr != st.end(); itr++) {
    ret.push_back(*itr);
  }
  return ret;
}


// the line through 2 coordinates
line line_through_2_coordinates(coordinate p, coordinate q) {
  if (p.x == q.x && p.y == q.y) return{ NAN, NAN, NAN, p, q };
  else {
    if (p.x == q.x) {
      if (p.y < q.y) return { 1, 0, -p.x, p, q };
      else return{ 1, 0, -p.x, q, p };
    }
    else {
      if (p.x < q.x) return { (q.y - p.y), (p.x - q.x), q.x * p.y - p.x * q.y, p, q };
      else return{ (q.y - p.y), (p.x - q.x), q.x * p.y - p.x * q.y, q, p };
    }
  }
}



int main() {
  int q; cin >> q;
  cout << setprecision(18);
  Loop(i, q) {
    coordinate p, q;
    line s, t;
    cin >> p.x >> p.y >> q.x >> q.y;
    s = line_through_2_coordinates(p, q);
    cin >> p.x >> p.y >> q.x >> q.y;
    t = line_through_2_coordinates(p, q);
    coordinate r = cross_of_2_lines(s, t);
    if (_isnan(r.x)) cout << 0 << endl;
    else cout << 1 << endl;
  }
}


Compiler output:
a.cc: In function 'std::vector<coordinate> crosses_of_lines(std::vector<line>)':
a.cc:90:12: error: '_isnan' was not declared in this scope; did you mean '__isnan'?
   90 |       if (!_isnan(p.x )&& !_isnan(p.y)) st.insert(p);
      |            ^~~~~~
      |            __isnan
a.cc: In function 'int main()':
a.cc:129:9: error: '_isnan' was not declared in this scope; did you mean '__isnan'?
  129 |     if (_isnan(r.x)) cout << 0 << endl;
      |         ^~~~~~
      |         __isnan