<commit_before>#include <stan/math/prim.hpp>
#include <gtest/gtest.h>
#include <limits>

TEST(MathFunctionsLog, inv_Phi_log) {
  using stan::math::inv_Phi_log;
  using stan::math::Phi;
  EXPECT_FLOAT_EQ(0.0, inv_Phi_log(log(0.5)));
  double log_p = log(0.123456789);
  EXPECT_FLOAT_EQ(0.123456789, Phi(inv_Phi_log(log_p)));
  log_p = log(8e-311);
  EXPECT_FLOAT_EQ(8e-311, Phi(inv_Phi_log(log_p)));
  log_p = log(0.99);
  EXPECT_FLOAT_EQ(0.99, Phi(inv_Phi_log(log_p)));

  // breakpoints
  log_p = log(0.02425);
  EXPECT_FLOAT_EQ(0.02425, Phi(inv_Phi_log(log_p)));
  log_p = log(0.97575);
  EXPECT_FLOAT_EQ(0.97575, Phi(inv_Phi_log(log_p)));
}

TEST(MathFunctionsLog, Equal) {
  using stan::math::inv_Phi_log;
  // test output generated with WolframAlpha

  long double log_p[]
      = {-20.72326583694641115616192309215927786840991339765895678429,
         -16.11809565095831978812594018279054945320771042040141083223,
         -11.51292546497022842008995727342182103800550744314386488016,
         -6.907755278982137052053974364053092622803304465886318928099,
         -2.995732273553990993435223576142540775676601622989028230154,
         -1.897119984885881302039978339220015071029111065166278778419,
         -1.386294361119890618834464242916353136151000268720510508241,
         -1.049822124498677688329870832699361046039516893407167041694,
         -0.798507696217771610644733102297489366381620507343529326684,
         -0.597837000755620449373279998177411475854894769051611054935,
         -0.430782916092454257381736134577222170871333678228821113734,
         -0.287682072451780927439219005993827431503509710897761056506,
         -0.162518929497774913185688958269414240088398610403283442856,
         -0.051293294387550533426196144254687238439222361689899411616,
         -0.001000500333583533500142982254068344960755205250434409250,
         -0.000010000050000333335833353333500001428583928682540682548,
         -1.000000050000003333333583333353333335000000142857155e-7,
         -1.000000000500000000333333333583333333533333333500000e-9};

  long double exact[]
      = {-5.9978070150076868715623102049115374195951202210145432633059905935,
         -5.199337582192816931587347266962336866509737160238716454318950531,
         -4.264890793922824628498524698906344629356053222695490726201050806,
         -3.090232306167813541540399830107379205491008491865808855697171108,
         -1.644853626951472714863848907991632136083195744275322071769672094,
         -1.036433389493789579713244074673503366134740595985917627904454866,
         -0.674489750196081743202227014541307185386904415049861895662093788,
         -0.385320466407567623810762390270473572721091620003945341485947546,
         -0.125661346855074034210184388300799303397350646690021834224555394,
         0.1256613468550740342101843883007993033973506466900218342245553948,
         0.3853204664075676238107623902704735727210916200039453414859475461,
         0.6744897501960817432022270145413071853869044150498618956620937885,
         1.0364333894937895797132440746735033661347405959859176279044548663,
         1.6448536269514727148638489079916321360831957442753220717696720944,
         3.0902323061678135415403998301073792054910084918658088556971711085,
         4.2648907939228246284985246989063446293560532226954907262010508062,
         5.1993375821928169315873472669623368665097371602387164543189505310,
         5.9978070150076868715623102049115374195951202210145432633059905935};

  int numValues = sizeof(log_p) / sizeof(long double);

  for (int i = 0; i < numValues; ++i) {
    EXPECT_NEAR(exact[i], inv_Phi_log(log_p[i]), 1.5e-15);
  }
}

TEST(MathFunctionsLog, inv_Phi_log_inf) {
  using stan::math::inv_Phi_log;
  long double log_p = std::numeric_limits<long double>::min();
  const double inf = std::numeric_limits<double>::infinity();
  EXPECT_EQ(inv_Phi_log(-inf), -inf);
  log_p = log(1.);
  EXPECT_EQ(inv_Phi_log(log_p), inf);
}

TEST(MathFunctionsLog, inv_Phi_log_nan) {
  using stan::math::inv_Phi_log;<commit_msg>update prim test<commit_after>#include <stan/math/prim.hpp>
#include <gtest/gtest.h>
#include <limits>

TEST(MathFunctionsLog, inv_Phi_log) {
  using stan::math::inv_Phi_log;
  using stan::math::Phi;
  EXPECT_FLOAT_EQ(0.0, inv_Phi_log(log(0.5)));
  double log_p = log(0.123456789);
  EXPECT_FLOAT_EQ(0.123456789, Phi(inv_Phi_log(log_p)));
  log_p = log(8e-311);
  EXPECT_FLOAT_EQ(8e-311, Phi(inv_Phi_log(log_p)));
  log_p = log(0.99);
  EXPECT_FLOAT_EQ(0.99, Phi(inv_Phi_log(log_p)));

  // breakpoints
  log_p = log(0.02425);
  EXPECT_FLOAT_EQ(0.02425, Phi(inv_Phi_log(log_p)));
  log_p = log(0.97575);
  EXPECT_FLOAT_EQ(0.97575, Phi(inv_Phi_log(log_p)));
}

TEST(MathFunctionsLog, Equal) {
  using stan::math::inv_Phi_log;
  // test output generated with WolframAlpha

 double log_p[]
      = {-20.72326583694641115,
         -16.11809565095831978,
         -11.51292546497022842,
         -6.907755278982137052,
         -2.995732273553990993,
         -1.897119984885881302,
         -1.386294361119890618,
         -1.049822124498677688,
         -0.798507696217771610,
         -0.597837000755620449,
         -0.430782916092454257,
         -0.287682072451780927,
         -0.162518929497774913,
         -0.051293294387550533,
         -0.001000500333583533,
         -0.000010000050000333,
         -1.000000050000003e-7,
         -1.000000000500000e-9};

  double exact[]
      = {-5.997807015007686871,
         -5.199337582192816931,
         -4.264890793922824628,
         -3.090232306167813541,
         -1.644853626951472714,
         -1.036433389493789579,
         -0.674489750196081743,
         -0.385320466407567623,
         -0.125661346855074034,
         0.1256613468550740342,
         0.3853204664075676238,
         0.6744897501960817432,
         1.0364333894937895797,
         1.6448536269514727148,
         3.0902323061678135415,
         4.2648907939228246284,
         5.1993375821928169315,
         5.9978070150076868715};

  int numValues = sizeof(log_p) / sizeof(double);

  for (int i = 0; i < numValues; ++i) {
    EXPECT_NEAR(exact[i], inv_Phi_log(log_p[i]), 9.5e-14);
  }
}

TEST(MathFunctionsLog, inv_Phi_log_inf) {
  using stan::math::inv_Phi_log;
  long double log_p = std::numeric_limits<long double>::min();
  const double inf = std::numeric_limits<double>::infinity();
  EXPECT_EQ(inv_Phi_log(-inf), -inf);
  log_p = log(1.);
  EXPECT_EQ(inv_Phi_log(log_p), inf);
}

TEST(MathFunctionsLog, inv_Phi_log_nan) {
  using stan::math::inv_Phi_log;
{'fraction_non_alphanumeric': 0.10003077870113881, 'fraction_numerical': 0.4649122807017544, 'mean_word_length': 4.178486055776893, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 9, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220020', 'n_tokens_mistral': 4452, 'n_tokens_neox': 2759, 'n_words': 248}