<commit_before>/* This file is part of Metallic, a runtime library for WebAssembly.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla
 * Public License v. 2.0. If a copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
#include "kernel/atanhf.h"
#include "reducef.h"
#include "quietf.h"
#include <math.h>

static double _finite(double x)
{
    const double log10_e2 = 0.8685889638065036553;
    const double log10_2 = 0.3010299956639811952;

    int exponent;

    x = reducef(x, &exponent);

    return log10_e2 * __kernel_atanhf((x - 1) / (x + 1)) + exponent * log10_2;
}

float log10f(float x)
{
    const int32_t inf = 0x7F800000;

    if (x == 0)
        return -HUGE_VALF;

    int32_t i = *(int32_t*)&x;

    if (i < 0)
        return __quietf(x);

    if (i < inf)
        return _finite(x);

    return x;
}<commit_msg>New implementation of log10f<commit_after>/* This file is part of Metallic, a runtime library for WebAssembly.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla
 * Public License v. 2.0. If a copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
#include "../reinterpret.h"
#include "kernel/atanhf.h"
#include "normalizef.h"
#include "quietf.h"
#include <float.h>
#include <math.h>

static float _finite(int32_t i)
{
    const double log10_e = 0.43429448190325182765;
    const double log10_2 = 0.30102999566398119521;

    int32_t exponent = (i - 0x3F3504F4) >> (FLT_MANT_DIG - 1);
    double x = __reinterpretf(i - (exponent << (FLT_MANT_DIG - 1)));

    return 2 * log10_e * __kernel_atanhf((x - 1) / (x + 1)) + exponent * log10_2;
}

float log10f(float x)
{
    int32_t i = __bitsf(x);

    if (i < 0)
        return i << 1 == 0 ? -HUGE_VALF : __quietf(x);

    if (i < 0x7F800000)
        return _finite(__normalizef(i));

    return x;
}
{'fraction_non_alphanumeric': 0.1265632816408204, 'fraction_numerical': 0.0865432716358179, 'mean_word_length': 3.024144869215292, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '7348853', 'n_tokens_mistral': 878, 'n_tokens_neox': 747, 'n_words': 232}