<commit_before>package math

import "GoVM/chapter5-instructions/base"

/**
	取余指令
 */
type DREM struct {
	base.NoOperandsInstruction
}

type FREM struct {
	base.NoOperandsInstruction
}

type IREM struct {
	base.NoOperandsInstruction
}

type LREM struct {
	base.NoOperandsInstruction
}<commit_msg>rem 指令 完善<commit_after>package math

import (
	"GoVM/chapter5-instructions/base"
	"GoVM/chapter4-rtdt"
	"math"
)

/**
	取余指令
 */
type DREM struct {
	base.NoOperandsInstruction
}

/**
	浮点数有Infinity -> 无限大值，所以即使是除0 也不会ArithmeticException
 */
func (self *DREM) Execute(frame *chapter4_rtdt.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopDouble()
	v1 := stack.PopDouble()
	result := math.Mod(v1, v2)
	stack.PushDouble(result)
}

type FREM struct {
	base.NoOperandsInstruction
}

func (self *FREM) Execute(frame *chapter4_rtdt.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopFloat()
	v1 := stack.PopFloat()
	result := math.Mod(v1, v2)
	stack.PushDouble(result)
}

type IREM struct {
	base.NoOperandsInstruction
}

func (self *IREM) Execute(frame *chapter4_rtdt.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopInt()
	if v2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	result := v1 % v2
	stack.PushInt(result)
}

type LREM struct {
	base.NoOperandsInstruction
}

func (self *LREM) Execute(frame *chapter4_rtdt.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopLong()
	v1 := stack.PopLong()
	if v2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	result := v1 % v2
	stack.PushInt(result)
}
{'fraction_non_alphanumeric': 0.13846153846153847, 'fraction_numerical': 0.017948717948717947, 'mean_word_length': 4.401384083044983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3497090', 'n_tokens_mistral': 651, 'n_tokens_neox': 638, 'n_words': 121}