<commit_before>package com.annimon.ownlang.lib.modules;

import com.annimon.ownlang.lib.Function;
import com.annimon.ownlang.lib.Functions;
import com.annimon.ownlang.lib.NumberValue;
import com.annimon.ownlang.lib.Value;

/**
 *
 * @author aNNiMON
 */
public final class math implements Module {

    @Override
    public void init() {
        Functions.set("sin", args -> {
            if (args.length != 1) throw new RuntimeException("One arg expected");
            return new NumberValue(Math.sin(args[0].asNumber()));
        });
        Functions.set("cos", args -> {
            if (args.length != 1) throw new RuntimeException("One arg expected");
            return new NumberValue(Math.cos(args[0].asNumber()));
        });
    }

}
<commit_msg>Добавлены функции в модуль math<commit_after>package com.annimon.ownlang.lib.modules;

import com.annimon.ownlang.lib.*;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleFunction;
import java.util.function.DoubleUnaryOperator;

/**
 *
 * @author aNNiMON
 */
public final class math implements Module {
    
    private static final DoubleFunction<NumberValue> doubleToNumber = v -> new NumberValue(v);

    @Override
    public void init() {
        Functions.set("abs", functionConvert(Math::abs));
        Functions.set("cos", functionConvert(Math::cos));
        Functions.set("sin", functionConvert(Math::sin));
        Functions.set("sqrt", functionConvert(Math::sqrt));
        Functions.set("toDegrees", functionConvert(Math::toDegrees));
        Functions.set("toRadians", functionConvert(Math::toRadians));
        
        Functions.set("pow", biFunctionConvert(Math::pow));
        Functions.set("atan2", biFunctionConvert(Math::atan2));
        
        Variables.set("PI", new NumberValue(Math.PI));
        Variables.set("E", new NumberValue(Math.E));
    }
    
    private static Function functionConvert(DoubleUnaryOperator op) {
        return args -> {
            if (args.length != 1) throw new RuntimeException("One arg expected");
            return doubleToNumber.apply(op.applyAsDouble(args[0].asNumber()));
        };
    }
    
    private static Function biFunctionConvert(DoubleBinaryOperator op) {
        return args -> {
            if (args.length != 2) throw new RuntimeException("Two args expected");
            return doubleToNumber.apply(op.applyAsDouble(args[0].asNumber(), args[1].asNumber()));
        };
    }
}

{'fraction_non_alphanumeric': 0.1360098320360508, 'fraction_numerical': 0.004506349856616141, 'mean_word_length': 3.188679245283019, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, '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': '6262480', 'n_tokens_mistral': 712, 'n_tokens_neox': 686, 'n_words': 139}