/** * validate * * test validation function for values returning NaN */ void __cdecl validate_isnan(float value) { float result = asinf(value); if (!_isnanf(result)) { Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", value, result, PAL_NAN); } }
void LogLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { NeuronLayer<Dtype>::LayerSetUp(bottom, top); const Dtype base = this->layer_param_.log_param().base(); if (base != Dtype(-1)) { CHECK_GT(base, 0) << "base must be strictly positive."; } // If base == -1, interpret the base as e and set log_base = 1 exactly. // Otherwise, calculate its log explicitly. const Dtype log_base = (base == Dtype(-1)) ? Dtype(1) : log(base); CHECK(!_isnanf(log_base)) << "NaN result: log(base) = log(" << base << ") = " << log_base; CHECK(_finitef(log_base)) << "Inf result: log(base) = log(" << base << ") = " << log_base; base_scale_ = Dtype(1) / log_base; CHECK(!_isnanf(base_scale_)) << "NaN result: 1/log(base) = 1/log(" << base << ") = " << base_scale_; CHECK(_finitef(base_scale_)) << "Inf result: 1/log(base) = 1/log(" << base << ") = " << base_scale_; input_scale_ = this->layer_param_.log_param().scale(); input_shift_ = this->layer_param_.log_param().shift(); backward_num_scale_ = input_scale_ / log_base; }
/* * NaN: any float with maximum exponent (0x7f8) and non-zero fraction */ int __cdecl main(int argc, char *argv[]) { /* * Initialize the PAL and return FAIL if this fails */ if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /* * Try some trivial values */ if (_isnanf(0.0f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 0.0f); } if (_isnanf(1.234567f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 1.234567f); } if (_isnanf(42.0f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 42.0f); } UINT32 lneginf = 0xff800000u; UINT32 lposinf = 0x7f800000u; float neginf = TO_FLOAT(lneginf); float posinf = TO_FLOAT(lposinf); /* * Try positive and negative infinity */ if (_isnanf(neginf)) { Fail("_isnanf() incorrectly identified negative infinity as NaN!\n"); } if (_isnanf(posinf)) { Fail("_isnanf() incorrectly identified infinity as NaN!\n"); } /* * Try setting the least significant bit of the fraction, * positive and negative */ UINT32 lsnan = 0xff800001u; float snan = TO_FLOAT(lsnan); if (!_isnanf(snan)) { Fail("_isnanf() failed to identify %I32x as NaN!\n", lsnan); } UINT32 lqnan = 0x7f800001u; float qnan = TO_FLOAT(lqnan); if (!_isnanf(qnan)) { Fail("_isnanf() failed to identify %I32x as NaN!\n", lqnan); } /* * Try setting the most significant bit of the fraction, * positive and negative */ lsnan = 0xffc00000u; snan = TO_FLOAT(lsnan); if (!_isnanf(snan)) { Fail ("_isnanf() failed to identify %I32x as NaN!\n", lsnan); } lqnan = 0x7fc00000u; qnan = TO_FLOAT(lqnan); if (!_isnanf(qnan)) { Fail ("_isnanf() failed to identify %I32x as NaN!\n", lqnan); } PAL_Terminate(); return PASS; }