/* Displaying messages and getting input for Lynx Browser ** ========================================================== ** ** REPLACE THIS MODULE with a GUI version in a GUI environment! ** ** History: ** Jun 92 Created May 1992 By C.T. Barker ** Feb 93 Simplified, portablised TBL ** */ #include #include #include #include #include #include #include #include #include #include /* store statusline messages */ #include #include /* Issue a message about a problem. HTAlert() ** -------------------------------- */ PUBLIC void HTAlert ARGS1( CONST char *, Msg) { CTRACE((tfp, "\nAlert!: %s\n\n", Msg)); CTRACE_FLUSH(tfp); _user_message(ALERT_FORMAT, Msg); LYstore_message2(ALERT_FORMAT, Msg); LYSleepAlert(); } PUBLIC void HTAlwaysAlert ARGS2( CONST char *, extra_prefix, CONST char *, Msg) { if (!dump_output_immediately && LYCursesON) { HTAlert(Msg); } else { if (extra_prefix) { fprintf(((TRACE) ? stdout : stderr), "%s %s!\n", extra_prefix, Msg); fflush(stdout); LYstore_message2(ALERT_FORMAT, Msg); LYSleepAlert(); } else { fprintf(((TRACE) ? stdout : stderr), ALERT_FORMAT, (Msg == 0) ? "" : Msg); fflush(stdout); LYstore_message2(ALERT_FORMAT, Msg); LYSleepAlert(); fprintf(((TRACE) ? stdout : stderr), "\n"); } CTRACE((tfp, "\nAlert!: %s\n\n", Msg)); CTRACE_FLUSH(tfp); } } /* Issue an informational message. HTInfoMsg() ** -------------------------------- */ PUBLIC void HTInfoMsg ARGS1( CONST char *, Msg) { _statusline(Msg); if (Msg && *Msg) { CTRACE((tfp, "Info message: %s\n", Msg)); LYstore_message(Msg); sleep(InfoSecs); } } /* Issue an important message. HTUserMsg() ** -------------------------------- */ PUBLIC void HTUserMsg ARGS1( CONST char *, Msg) { _statusline(Msg); if (Msg && *Msg) { CTRACE((tfp, "User message: %s\n", Msg)); LYstore_message(Msg); LYSleepMsg(); } } PUBLIC void HTUserMsg2 ARGS2( CONST char *, Msg2, CONST char *, Arg) { _user_message(Msg2, Arg); if (Msg2 && *Msg2) { CTRACE((tfp, "User message: ")); CTRACE((tfp, Msg2, Arg)); CTRACE((tfp, "\n")); LYstore_message2(Msg2, Arg); LYSleepMsg(); } } /* Issue a progress message. HTProgress() ** ------------------------- */ PUBLIC void HTProgress ARGS1( CONST char *, Msg) { statusline(Msg); LYstore_message(Msg); CTRACE((tfp, "%s\n", Msg)); #if defined(SH_EX) && defined(WIN_EX) /* 1997/10/11 (Sat) 12:51:02 */ { if (debug_delay != 0) Sleep(debug_delay); /* XXX msec */ } #endif } #ifdef EXP_READPROGRESS PRIVATE char *sprint_bytes ARGS3( char *, s, long, n, char *, was_units) { static long kb_units = 1024; static char *bunits; static char *kbunits; char *u; if (!bunits) { bunits = gettext("bytes"); kbunits = gettext("KB"); } u = kbunits; if (LYshow_kb_rate && (n >= 10 * kb_units)) sprintf(s, "%ld", n/kb_units); else if (LYshow_kb_rate && (n >= kb_units)) sprintf(s, "%.2g", ((double)n)/kb_units); else { sprintf(s, "%ld", n); u = bunits; } if (!was_units || was_units != u) sprintf(s + strlen(s), " %s", u); return u; } #endif /* EXP_READPROGRESS */ /* Issue a read-progress message. HTReadProgress() ** ------------------------------ */ PUBLIC void HTReadProgress ARGS2( long, bytes, long, total) { #ifdef WIN_EX /* 1998/07/08 (Wed) 16:09:47 */ #include #define kb_units 1024L static double now, first, last; static long bytes_last; double transfer_rate; char line[MAX_LINE]; struct timeb tb; char *units = "bytes"; ftime(&tb); now = tb.time + (double)tb.millitm / 1000; if (bytes == 0) { first = last = now; bytes_last = bytes; } else if ((bytes > 0) && (now > first)) { transfer_rate = (double)bytes / (now - first); /* bytes/sec */ if (now != last) { last = now; bytes_last = bytes; } if (LYshow_kb_rate && (total >= kb_units || bytes >= kb_units)) { if (total > 0) total /= 1024; bytes /= 1024; units = "KB"; } if (total > 0) sprintf (line, "Read %3d%%, %ld of %ld %s.", (int) (bytes * 100 / total), bytes, total, units); else sprintf (line, "Read %ld %s of data.", bytes, units); if (transfer_rate > 0.0) { int n; n = strlen(line); if (LYshow_kb_rate) { sprintf (line + n, " %6.2f KB/sec.", transfer_rate / 1024.0); } else { int t_rate; t_rate = (int)transfer_rate; if (t_rate < 1000) sprintf (line + n, " %6d bytes/sec.", t_rate); else sprintf (line + n, " %6d,%03d bytes/sec.", t_rate / 1000, t_rate % 1000); } } if (total < 0) { if (total < -1) strcat(line, " (Press 'z' to abort)"); } statusline(line); } #else /* !WIN_EX */ #ifdef EXP_READPROGRESS static long bytes_last, total_last; static long transfer_rate = 0; static char *line = NULL; char bytesp[80], totalp[80], transferp[80]; int renew = 0; char *was_units; #if HAVE_GETTIMEOFDAY struct timeval tv; int dummy = gettimeofday(&tv, (struct timezone *)0); double now = tv.tv_sec + tv.tv_usec/1000000. ; static double first, last, last_active; #else time_t now = time((time_t *)0); /* once per second */ static time_t first, last, last_active; #endif if (bytes == 0) { first = last = last_active = now; bytes_last = bytes; } else if (bytes < 0) { /* stalled */ bytes = bytes_last; total = total_last; } if ((bytes > 0) && (now != first)) /* 1 sec delay for transfer_rate calculation without g-t-o-d */ { if (transfer_rate <= 0) /* the very first time */ transfer_rate = (bytes) / (now - first); /* bytes/sec */ total_last = total; /* * Optimal refresh time: every 0.2 sec, use interpolation. Transfer * rate is not constant when we have partial content in a proxy, so * interpolation lies - will check every second at least for sure. */ #if HAVE_GETTIMEOFDAY if (now >= last + 0.2) renew = 1; #else if (((bytes - bytes_last) > (transfer_rate / 5)) || (now != last)) { renew = 1; bytes_last += (transfer_rate / 5); /* until we got next second */ } #endif if (renew) { if (now != last) { last = now; if (bytes_last != bytes) last_active = now; bytes_last = bytes; transfer_rate = bytes / (now - first); /* more accurate here */ } if (total > 0) was_units = sprint_bytes(totalp, total, 0); else was_units = 0; sprint_bytes(bytesp, bytes, was_units); sprint_bytes(transferp, transfer_rate, 0); if (total > 0) HTSprintf0 (&line, gettext("Read %s of %s of data"), bytesp, totalp); else HTSprintf0 (&line, gettext("Read %s of data"), bytesp); if (transfer_rate > 0) HTSprintf (&line, gettext(", %s/sec"), transferp); if (now - last_active >= 5) HTSprintf (&line, gettext(" (stalled for %ld sec)"), (long)(now - last_active)); if (total > 0 && transfer_rate) HTSprintf (&line, gettext(", ETA %ld sec"), (long)((total - bytes)/transfer_rate)); StrAllocCat (line, "."); if (total < -1) StrAllocCat(line, gettext(" (Press 'z' to abort)")); /* do
discard """
  targets: "c c++ js"
  output: "ok"
  exitcode: "0"
"""

# Test `mod` on float64 both at compiletime and at runtime
import math

# Testdata from golang
const testValues: array[10, tuple[f64, expected: float64]] = [
  (4.9790119248836735e+00, 4.197615023265299782906368e-02),
  (7.7388724745781045e+00, 2.261127525421895434476482e+00),
  (-2.7688005719200159e-01, 3.231794108794261433104108e-02),
  (-5.0106036182710749e+00, 4.989396381728925078391512e+00),
  (9.6362937071984173e+00, 3.637062928015826201999516e-01),
  (2.9263772392439646e+00, 1.220868282268106064236690e+00),
  (5.2290834314593066e+00, 4.770916568540693347699744e+00),
  (2.7279399104360102e+00, 1.816180268691969246219742e+00),
  (1.8253080916808550e+00, 8.734595415957246977711748e-01),
  (-8.6859247685756013e+00, 1.314075231424398637614104e+00)]

const simpleTestData = [
  (5.0, 3.0, 2.0),
  (5.0, -3.0, 2.0),
  (-5.0, 3.0, -2.0),
  (-5.0, -3.0, -2.0),
  (10.0, 1.0, 0.0),
  (10.0, 0.5, 0.0),
  (10.0, 1.5, 1.0),
  (-10.0, 1.0, -0.0),
  (-10.0, 0.5, -0.0),
  (-10.0, 1.5, -1.0),
  (1.5, 1.0, 0.5),
  (1.25, 1.0, 0.25),
  (1.125, 1.0, 0.125)
  ]

const specialCases = [
  (-Inf, -Inf, Nan),
  (-Inf, -Pi, Nan),
  (-Inf, 0.0, Nan),
  (-Inf, Pi, Nan),
  (-Inf, Inf, Nan),
  (-Inf, Nan, Nan),
  (-PI, -Inf, -PI),
  (-PI, 0.0, Nan),
  (-PI, Inf, -PI),
  (-PI, Nan, Nan),
  (-0.0, -Inf, -0.0),
  (-0.0, 0.0, Nan),
  (-0.0, Inf, -0.0),
  (-0.0, Nan, Nan),
  (0.0, -Inf, 0.0),
  (0.0, 0.0, Nan),
  (0.0, Inf, 0.0),
  (0.0, Nan, Nan),
  (PI, -Inf, PI),
  (PI, 0.0, Nan),
  (PI, Inf, PI),
  (PI, Nan, Nan),
  (Inf, -Inf, Nan),
  (Inf, -PI, Nan),
  (Inf, 0.0, Nan),
  (Inf, PI, Nan),
  (Inf, Inf, Nan),
  (Inf,