Sha256: 6c5f8c5a69bc8279944e3aa6bf6ab4005229f0e84bf14c096ec3e47515c91a33

Contents?: true

Size: 962 Bytes

Versions: 82

Compression:

Stored size: 962 Bytes

Contents

import math,strutils

proc fixedWidth(input: string, minFieldSize: int):string {.inline.} =
  # Note that field size is a minimum- will expand field if input
  # string is larger
  if input.startsWith("-"):
    return(input & repeatchar(count=(abs(minFieldSize-len(input))),c=' '))
  else:
    return(" " & input & repeatchar(count=(abs(minFieldSize-len(input))-1),c=' '))

template mathOnInterval(lowbound,highbound:float,counts: int,p:proc) =
  block:
    var step:    float = (highbound - lowbound)/(max(counts,1))
    var current: float = lowbound
    while current < highbound:
      echo($fixedWidth($current,25) & ": " & $fixedWidth($p(current),25))
      current += step

echo "Sine of theta from 0 to 2*PI by PI/12"
mathOnInterval(0.0,2.0*PI,12,sin)
echo("\n")
echo "Cosine of theta from 0 to 2*PI by PI/12"
mathOnInterval(0.0,2.0*PI,12,cos)

# The first example above is much the same as:
# for i in 1..100:
#   echo($sin( (float(i)/100.0) * 2.0*PI ))

Version data entries

82 entries across 80 versions & 9 rubygems

Version Path
rouge-4.5.1 lib/rouge/demos/nim
rouge-4.5.0 lib/rouge/demos/nim
rouge-4.4.0 lib/rouge/demos/nim
rouge-4.3.0 lib/rouge/demos/nim
rouge-4.2.1 lib/rouge/demos/nim
rouge-4.2.0 lib/rouge/demos/nim
rouge-4.1.3 lib/rouge/demos/nim
rouge-4.1.2 lib/rouge/demos/nim
rouge-4.1.1 lib/rouge/demos/nim
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/demos/nim
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/demos/nim
rouge-4.1.0 lib/rouge/demos/nim
rouge-4.0.1 lib/rouge/demos/nim
rouge-4.0.0 lib/rouge/demos/nim
rouge-3.30.0 lib/rouge/demos/nim
rouge-3.29.0 lib/rouge/demos/nim
rouge-3.28.0 lib/rouge/demos/nim
rouge-3.27.0 lib/rouge/demos/nim
rouge-3.26.1 lib/rouge/demos/nim
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/demos/nim