Language: C++

#include<iostream>
#include<cmath>
#include<complex>
#include<cassert>
#define ERROR 0x00
#define FRONT 0x01
#define RIGHT 0x02
#define BACK 0x04
#define LEFT 0x08
#define OVER 0x10
using namespace std;

typedef double elem;
typedef complex<elem> point, vec;
typedef pair<point, point > line;

const double eps = 1.0e-6;
const double pi = acos(-1.0);
bool eq(elem a, elem b){ return abs(b-a) < eps; }
bool lt(elem a, elem b){ return !eq(a,b) && a < b; }
bool leq(elem a, elem b){ return eq(a,b) || a < b; }
bool gt(elem a, elem b){ return !eq(a,b) && a > b; }
bool geq(elem a, elem b){ return eq(a,b) || a > b; }
bool ltz(elem a){ return lt( a, 0 ); }
bool gtz(elem a){ return gt( a, 0 ); }
vec uvec(vec v){ return v / abs(v); }
vec normr(vec v){ return v * vec(0,-1); }
struct circle{
  point c;
  elem r;
};
elem dot(vec a, vec b){
  return (a.real() * b.real() + a.imag() * b.imag() );
}
elem arg(vec a, vec b){
  return acos( dot(a,b) / (abs(a)*abs(b)) );
}
elem cross(vec a, vec b){
  return ( a.real() * b.imag() - a.imag() * b.real() );
}
elem dist( point a, point b ){
  return abs(b-a);
}
elem dist_l(point a1, point a2, point x){
  return abs(cross(a2-a1,x-a1)) / abs(a2-a1);
}
point rot(point p, elem theta){
  return p * exp( point(0,theta) );
}
bool is_cl(circle &c, line l, pair<point,point> &ret){
  elem d = dist_l( l.first, l.second, c.c );
  if( d > c.r ){
    return false;
  }else{
    double L = sqrt( pow(c.r,2.0 )-pow( d,2.0 ) );
    vec p(l.second-l.first);
    p = uvec( p );
    p *= L;
    ret.first = p + c.c;
    p *= -1;
    ret.second = p + c.c;
  }
  return true;
}
int ccw(point a, point b, point x){
  vec vb = b - a;
  vec vx = x - a;
  elem z = cross( vb, vx );

  if( eq(abs(vb),0) )
    return ERR;

  if( eq(z,0) ){
    elem d_ab = dist(a,b);
    elem d_bx = dist(b,x);
    elem d_ax = dist(a,x);
    if( eq(d_ab,d_ax+d_bx) )
      return OVER;
    if( gt( d_ax, d_ab ) && gt( d_ax, d_bx ) )
      return FRONT;
    if( gt( d_bx, d_ab ) && gt( d_bx, d_ax ) )
      return BACK;
  }else if( gtz( z ) )
    return LEFT;
  else if( ltz( z ) )
    return RIGHT;
  return ERROR;
}

double NextRailgun(double D, point p, vec v, point &np, vec &nv){
  double left = D;
  circle uc;
  pair<point, point> cross;

  uc.r = 1;
  uc.c = point(0,0);
  if( is_cl( uc, line(p,v), cross ) ){
    np = cross.first;
    if( ccw(p,v,np) == BACK )
      np = cross.second;
  }
  // tangential
  vec tang = np - uc.c;
  tang = normr(tang);
  elem Arg = arg( tang, v );
  elem rotArg = Arg;
  if( Arg > pi / 2 ){
    Arg = pi - Arg;
    rotArg = -(pi-2*Arg);
  }
  nv = np - p;
  nv = rot( nv, rotArg );
  nv = uvec( nv );
  nv *= abs(v);

  //cout << "Next : " << np << " Verocity: " << nv << endl;

  return dist(np,p);
}

int main(){
  while(true){
    double ans=0,orgD, D;
    cin >> D;
    orgD = D;
    if( eq(D,0) )break;
    double px,py,vx,vy;
    cin >> px >> py >> vx >> vy;
    point p(px,py);
    vec v(vx,vy);
    if( dist(p,point(0,0)) >= 1 ){
      cout << "impossible" << endl;
      continue;
    }
    bool bOk = false;
    point pp = p, pv = v;
    point np = p, nv = v;
    while(true){
      pp = np;
      pv = nv;
      elem progress = NextRailgun( D, p, v, np, nv );
      assert( progress > eps );
      ans += progress;
      //cout << "Point: " << p << " Velo : " << v << "Next : " << np << " NVelo : " << nv << endl;
      if( eq( dist_l(p,np,point(0,0)), 0 ) ){
	ans -= dist( np, point(0,0) );
	bOk = true;
	break;
      }
      if( ans > D ){
	break;
      }
    }
    if( bOk )
      printf("%.8lf\n", ans );
    else
      cout << "impossible" << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int ccw(point, point, point)':
a.cc:71:12: error: 'ERR' was not declared in this scope
   71 |     return ERR;
      |            ^~~