Top

$frac()


mIRC Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  May 12, 2009
Last Updated  May 13, 2009
Tags  awesome.  buddha  converter  decimal  editor  firstmate  frac  fraction  god  hawkee  inputoutput  jesus  math  mirc  mp3  mymother  playlist 

Introduction

I don't think it's a too difficult of a script to make, but I'll post it since I've never seen it.
Turns decimals into fractions. yay

Sample output:
Code:

$div(.5) -> 1/2
$div(.333) -> 1/3
$div(1.5) -> 3/2
$div(.342857) -> 12/35


A note on the number of significant figures. When doing something like 12/35 where the number of sigfigs is exactly 6, try to use 6. On numbers such as 1/3 where its continuous, it's recommended to use 4.

Grab the Code

alias frac {
  var %x 1,%t $mid($1,$pos($1,.,1),0) - 1,%p
  while (%x) {
    %p = $round($calc($v1 * $1),0)
    if ($round($calc($+(%p,/,$v1)),%t) == $1) return $+(%p,/,%x)
    inc %x
  }
}
 
 

Comments

  (3)  RSS
WorldDMT
Comments: 171
 
mIRC Snippet:  $frac()
Posted on May 13, 2009 11:13 am
hi

sorry about my language i don't speak verry well english

no need to "return $false"

u was declared %p local why u retype var %p down? type only %p = ...

the variable %y and %t just for len of number after the point?

put only "%t $mid($1,$pos($1,.,1),0) - 1"

no need $round($1,%t) type only $1 cz the %t is the len of number after the point

so
Code:
alias frac {
  var %x 1,%t $mid($1,$pos($1,.,1),0) - 1,%p
  while (%x) {
    %p = $round($calc($v1 * $1),0)
    if ($round($calc($+(%p,/,$v1)),%t) == $1) return $+(%p,/,%x)
    inc %x
  }
}
Firstmate
Comments: 119
 
mIRC Snippet:  $frac()
Posted on May 13, 2009 5:43 pm
Thanks, kinda did in a rush, but that's no excuse :p
knoeki
Comments: 120
 
mIRC Snippet:  $frac()
Posted on May 16, 2009 8:52 pm
Quote:
Thanks, kinda did in a rush, but that's no excuse :p


sure it is, it just isn't a really good one ;_)


(admittedly, I tend to use it too often as well..)

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom