<commit_before>package main

import (
  "fmt"
)

func main() {
  oneHalf := makeRat(1,2)
  oneThird := makeRat(1,3)
  printRat(addRat(oneThird, oneThird))
  fmt.Println(equalRat(oneThird, oneHalf))
}

type Rat struct {
    numer, denom int
}

func makeRat(n int, d int) Rat {
  // check if fraction is negative and remove negatives
  isNeg := false
  if (n < 0 && d < 0) {
    isNeg = false
    n *= -1
    d *= -1
  } else if (n < 0) {
    isNeg = true
    n *= -1
  } else if (d < 0) {
    isNeg = true
    d *= -1
  }

  // find greatest common divisor
  comDiv := gcd(n, d)
  n = n / comDiv
  d = d / comDiv

  // readd negative to numerator
  if (isNeg) {
    n *= -1
  }

  return Rat{n, d}
}

func numer(x Rat) int {
  return x.numer
}

func denom(x Rat) int {
  return x.denom
}

func addRat(x Rat, y Rat) Rat {
  thisNumer := (x.numer * y.denom) + (x.denom * y.numer)
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func subRat(x Rat, y Rat) Rat {
  thisNumer := (x.numer * y.denom) - (x.denom * y.numer)
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func mulRat(x Rat, y Rat) Rat {
  thisNumer := x.numer * y.numer
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func divRat(x Rat, y Rat) Rat {
  thisNumer := x.numer * y.denom
  thisDenom := x.denom * y.numer
  return makeRat(thisNumer, thisDenom)
}

func equalRat(x Rat, y Rat) bool {
  if (x.numer == y.numer && x.denom == y.denom) {
    return true
  }
  return false
}

func printRat(x Rat) {
   fmt.Printf("%d/%d\n", x.numer, x.denom)
}

// Euclid's Algorithm
func gcd(a int, b int) int {
  if (b == 0) {
    return a
  }
  return gcd(b, a % b)
}
<commit_msg>2.1 improved efficiency and abstraction of checking for negative ints<commit_after>package main

import (
  "fmt"
)

func main() {
  oneHalf := makeRat(1,2)
  oneThird := makeRat(1,3)
  printRat(addRat(oneThird, oneThird))
  fmt.Println(equalRat(oneThird, oneHalf))
}

type Rat struct {
    numer, denom int
}

func makeRat(n int, d int) Rat {
  // check if fraction is negative and remove negatives
  neg, n, d := isNeg(n, d)

  // find greatest common divisor
  comDiv := gcd(n, d)
  n = n / comDiv
  d = d / comDiv

  // if negative, add negative to numerator
  if (neg) {
    n *= -1
  }

  return Rat{n, d}
}

func numer(x Rat) int {
  return x.numer
}

func denom(x Rat) int {
  return x.denom
}

func addRat(x Rat, y Rat) Rat {
  thisNumer := (x.numer * y.denom) + (x.denom * y.numer)
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func subRat(x Rat, y Rat) Rat {
  thisNumer := (x.numer * y.denom) - (x.denom * y.numer)
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func mulRat(x Rat, y Rat) Rat {
  thisNumer := x.numer * y.numer
  thisDenom := x.denom * y.denom
  return makeRat(thisNumer, thisDenom)
}

func divRat(x Rat, y Rat) Rat {
  thisNumer := x.numer * y.denom
  thisDenom := x.denom * y.numer
  return makeRat(thisNumer, thisDenom)
}

func equalRat(x Rat, y Rat) bool {
  if (x.numer == y.numer && x.denom == y.denom) {
    return true
  }
  return false
}

func printRat(x Rat) {
   fmt.Printf("%d/%d\n", x.numer, x.denom)
}

// Euclid's Algorithm
func gcd(a int, b int) int {
  if (b == 0) {
    return a
  }
  return gcd(b, a % b)
}

func isNeg(n int, d int) (bool, int, int) {
  neg := false
  if (n < 0) {
    n *= -1
    neg = !neg
  }
  if (d < 0) {
    d *= -1
    neg = !neg
  }
  return neg, n, d
}

{'fraction_non_alphanumeric': 0.1462507155123068, 'fraction_numerical': 0.007441327990841442, 'mean_word_length': 2.6444212721584983, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3235372', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1441, 'n_words': 417}