replace all reference of float to float64

now works with last version of go
This commit is contained in:
legoff.laurent 2011-02-02 21:38:05 +00:00
parent 07bd88f868
commit af5f13b7f4
11 changed files with 56 additions and 55 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 264 KiB

View file

@ -3,12 +3,13 @@ package main
import ( import (
"fmt" "fmt"
) )
func main() { func main() {
toto := make([]int, 2, 2) toto := make([]int, 2, 2)
toto[0] = 1 toto[0] = 1
toto[1] = 2 toto[1] = 2
fmt.Printf("%v\n", toto); fmt.Printf("%v\n", toto)
toto = toto[0:0] toto = toto[0:0]
fmt.Printf("%v\n", toto); fmt.Printf("%v\n", toto)
fmt.Printf("%v\n", cap(toto)); fmt.Printf("%v\n", cap(toto))
} }

View file

@ -40,12 +40,12 @@ func main() {
i := image.NewRGBA(600, 800) i := image.NewRGBA(600, 800)
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
gc.Translate(0, 380) gc.Translate(0, 380)
gc.Scale(1,-1) gc.Scale(1, -1)
gc.Translate(0, -380) gc.Translate(0, -380)
lastTime := time.Nanoseconds() lastTime := time.Nanoseconds()
interpreter := postscript.NewInterpreter(gc) interpreter := postscript.NewInterpreter(gc)
interpreter.ExecuteFile("../../test_files/tiger.ps") interpreter.ExecuteFile("../../test_files/tiger.ps")
dt := time.Nanoseconds() - lastTime dt := time.Nanoseconds() - lastTime
fmt.Printf("Draw image: %f ms\n", float(dt)*1e-6) fmt.Printf("Draw image: %f ms\n", float64(dt)*1e-6)
saveToPngFile("../../TestPostscript.png", i) saveToPngFile("../../TestPostscript.png", i)
} }

View file

@ -96,7 +96,7 @@ func (interpreter *Interpreter) scan(scanner *Scanner, token int) {
// procedure // procedure
interpreter.Push(interpreter.scanProcedure(scanner)) interpreter.Push(interpreter.scanProcedure(scanner))
} else if token == Float || token == Int { } else if token == Float || token == Int {
f, err := strconv.Atof(scanner.TokenText()) f, err := strconv.Atof64(scanner.TokenText())
if err != nil { if err != nil {
log.Printf("Float expected: %s\n", scanner.TokenText()) log.Printf("Float expected: %s\n", scanner.TokenText())
interpreter.Push(scanner.TokenText()) interpreter.Push(scanner.TokenText())
@ -262,9 +262,9 @@ func (interpreter *Interpreter) ClearOperands() {
// misc pop // misc pop
func (interpreter *Interpreter) PopFloat() float { func (interpreter *Interpreter) PopFloat() float64 {
operand := interpreter.Pop() operand := interpreter.Pop()
return operand.(float) return operand.(float64)
} }
func (interpreter *Interpreter) PopInt() int { func (interpreter *Interpreter) PopInt() int {

View file

@ -11,7 +11,7 @@ func array(interpreter *Interpreter) {
} }
//array length int -> Return number of elements in array //array length int -> Return number of elements in array
func lengtharray(interpreter *Interpreter) { func lengtharray(interpreter *Interpreter) {
interpreter.Push(float(len(interpreter.Pop().([]Value)))) interpreter.Push(float64(len(interpreter.Pop().([]Value))))
} }
//array index get any -> Return array element indexed by index //array index get any -> Return array element indexed by index
func getarray(interpreter *Interpreter) { func getarray(interpreter *Interpreter) {

View file

@ -9,7 +9,7 @@ import (
// type dicriminant // type dicriminant
func commonCopy(interpreter *Interpreter) { func commonCopy(interpreter *Interpreter) {
switch v := interpreter.Peek().(type) { switch v := interpreter.Peek().(type) {
case float: case float64:
copystack(interpreter) copystack(interpreter)
case Dictionary: case Dictionary:
copydict(interpreter) copydict(interpreter)

View file

@ -53,7 +53,7 @@ func foroperator(interpreter *Interpreter) {
func repeat(interpreter *Interpreter) { func repeat(interpreter *Interpreter) {
proc := NewProcedure(interpreter.PopProcedureDefinition()) proc := NewProcedure(interpreter.PopProcedureDefinition())
times := interpreter.PopInt() times := interpreter.PopInt()
for i := 0; i <= times; i++ { for i := 0; i <= times; i++ {
proc.Execute(interpreter) proc.Execute(interpreter)
} }
} }

View file

@ -14,12 +14,12 @@ func dict(interpreter *Interpreter) {
//dict length int -> Return number of entries in dict //dict length int -> Return number of entries in dict
func lengthdict(interpreter *Interpreter) { func lengthdict(interpreter *Interpreter) {
dictionary := interpreter.Pop().(Dictionary) dictionary := interpreter.Pop().(Dictionary)
interpreter.Push(float(len(dictionary))) interpreter.Push(float64(len(dictionary)))
} }
//dict maxlength int -> Return current capacity of dict //dict maxlength int -> Return current capacity of dict
func maxlength(interpreter *Interpreter) { func maxlength(interpreter *Interpreter) {
interpreter.Pop() interpreter.Pop()
interpreter.Push(float(999999999)) // push arbitrary value interpreter.Push(float64(999999999)) // push arbitrary value
} }
//dict begin -> Push dict on dictionary stack //dict begin -> Push dict on dictionary stack
func begin(interpreter *Interpreter) { func begin(interpreter *Interpreter) {
@ -133,7 +133,7 @@ func statusdict(interpreter *Interpreter) {
} }
// countdictstack int -> Count elements on dictionary stack // countdictstack int -> Count elements on dictionary stack
func countdictstack(interpreter *Interpreter) { func countdictstack(interpreter *Interpreter) {
interpreter.Push(float(interpreter.DictionaryStackSize())) interpreter.Push(float64(interpreter.DictionaryStackSize()))
} }
//array dictstack subarray -> Copy dictionary stack into array //array dictstack subarray -> Copy dictionary stack into array
func dictstack(interpreter *Interpreter) { func dictstack(interpreter *Interpreter) {

View file

@ -77,7 +77,7 @@ func arc(interpreter *Interpreter) {
r := interpreter.PopFloat() r := interpreter.PopFloat()
y := interpreter.PopFloat() y := interpreter.PopFloat()
x := interpreter.PopFloat() x := interpreter.PopFloat()
interpreter.GetGraphicContext().ArcTo(x, y, r, r, angle1, angle2 - angle1) interpreter.GetGraphicContext().ArcTo(x, y, r, r, angle1, angle2-angle1)
} }
func clippath(interpreter *Interpreter) { func clippath(interpreter *Interpreter) {
@ -116,14 +116,14 @@ func setrgbcolor(interpreter *Interpreter) {
interpreter.GetGraphicContext().SetFillColor(color) interpreter.GetGraphicContext().SetFillColor(color)
} }
func hsbtorgb(hue, saturation, brightness float) (red, green, blue int) { func hsbtorgb(hue, saturation, brightness float64) (red, green, blue int) {
var fr, fg, fb float var fr, fg, fb float64
if saturation == 0 { if saturation == 0 {
fr, fg, fb = brightness, brightness, brightness fr, fg, fb = brightness, brightness, brightness
} else { } else {
H := (hue - float(math.Floor(float64(hue)))) * 6 H := (hue - math.Floor(hue)) * 6
I := int(math.Floor(float64(H))) I := int(math.Floor(H))
F := H - float(I) F := H - float64(I)
M := brightness * (1 - saturation) M := brightness * (1 - saturation)
N := brightness * (1 - saturation*F) N := brightness * (1 - saturation*F)
K := brightness * (1 - saturation*(1-F)) K := brightness * (1 - saturation*(1-F))
@ -335,10 +335,10 @@ func concatmatrix(interpreter *Interpreter) {
func transform(interpreter *Interpreter) { func transform(interpreter *Interpreter) {
value := interpreter.Pop() value := interpreter.Pop()
matrix, ok := value.(draw2d.MatrixTransform) matrix, ok := value.(draw2d.MatrixTransform)
var y float var y float64
if(!ok) { if !ok {
matrix = interpreter.GetGraphicContext().GetMatrixTransform() matrix = interpreter.GetGraphicContext().GetMatrixTransform()
y = value.(float) y = value.(float64)
} else { } else {
y = interpreter.PopFloat() y = interpreter.PopFloat()
} }
@ -351,10 +351,10 @@ func transform(interpreter *Interpreter) {
func itransform(interpreter *Interpreter) { func itransform(interpreter *Interpreter) {
value := interpreter.Pop() value := interpreter.Pop()
matrix, ok := value.(draw2d.MatrixTransform) matrix, ok := value.(draw2d.MatrixTransform)
var y float var y float64
if(!ok) { if !ok {
matrix = interpreter.GetGraphicContext().GetMatrixTransform() matrix = interpreter.GetGraphicContext().GetMatrixTransform()
y = value.(float) y = value.(float64)
} else { } else {
y = interpreter.PopFloat() y = interpreter.PopFloat()
} }
@ -367,15 +367,15 @@ func itransform(interpreter *Interpreter) {
func translate(interpreter *Interpreter) { func translate(interpreter *Interpreter) {
value := interpreter.Pop() value := interpreter.Pop()
matrix, ok := value.(draw2d.MatrixTransform) matrix, ok := value.(draw2d.MatrixTransform)
var y float var y float64
if(!ok) { if !ok {
matrix = interpreter.GetGraphicContext().GetMatrixTransform() matrix = interpreter.GetGraphicContext().GetMatrixTransform()
y = value.(float) y = value.(float64)
} else { } else {
y = interpreter.PopFloat() y = interpreter.PopFloat()
} }
x := interpreter.PopFloat() x := interpreter.PopFloat()
if(!ok) { if !ok {
interpreter.GetGraphicContext().Translate(x, y) interpreter.GetGraphicContext().Translate(x, y)
} else { } else {
matrix = draw2d.NewTranslationMatrix(x, y).Multiply(matrix) matrix = draw2d.NewTranslationMatrix(x, y).Multiply(matrix)
@ -386,14 +386,14 @@ func translate(interpreter *Interpreter) {
func rotate(interpreter *Interpreter) { func rotate(interpreter *Interpreter) {
value := interpreter.Pop() value := interpreter.Pop()
matrix, ok := value.(draw2d.MatrixTransform) matrix, ok := value.(draw2d.MatrixTransform)
var angle float var angle float64
if(!ok) { if !ok {
matrix = interpreter.GetGraphicContext().GetMatrixTransform() matrix = interpreter.GetGraphicContext().GetMatrixTransform()
angle = value.(float) * math.Pi / 180 angle = value.(float64) * math.Pi / 180
} else { } else {
angle = interpreter.PopFloat() * math.Pi / 180 angle = interpreter.PopFloat() * math.Pi / 180
} }
if(!ok) { if !ok {
interpreter.GetGraphicContext().Rotate(angle) interpreter.GetGraphicContext().Rotate(angle)
} else { } else {
matrix = draw2d.NewRotationMatrix(angle).Multiply(matrix) matrix = draw2d.NewRotationMatrix(angle).Multiply(matrix)
@ -404,15 +404,15 @@ func rotate(interpreter *Interpreter) {
func scale(interpreter *Interpreter) { func scale(interpreter *Interpreter) {
value := interpreter.Pop() value := interpreter.Pop()
matrix, ok := value.(draw2d.MatrixTransform) matrix, ok := value.(draw2d.MatrixTransform)
var y float var y float64
if(!ok) { if !ok {
matrix = interpreter.GetGraphicContext().GetMatrixTransform() matrix = interpreter.GetGraphicContext().GetMatrixTransform()
y = value.(float) y = value.(float64)
} else { } else {
y = interpreter.PopFloat() y = interpreter.PopFloat()
} }
x := interpreter.PopFloat() x := interpreter.PopFloat()
if(!ok) { if !ok {
interpreter.GetGraphicContext().Scale(x, y) interpreter.GetGraphicContext().Scale(x, y)
} else { } else {
matrix = draw2d.NewScaleMatrix(x, y).Multiply(matrix) matrix = draw2d.NewScaleMatrix(x, y).Multiply(matrix)

View file

@ -27,13 +27,13 @@ func div(interpreter *Interpreter) {
func idiv(interpreter *Interpreter) { func idiv(interpreter *Interpreter) {
int2 := interpreter.PopInt() int2 := interpreter.PopInt()
int1 := interpreter.PopInt() int1 := interpreter.PopInt()
interpreter.Push(float(int1 / int2)) interpreter.Push(float64(int1 / int2))
} }
//int int mod remainder -> Return remainder after dividing int by int //int int mod remainder -> Return remainder after dividing int by int
func mod(interpreter *Interpreter) { func mod(interpreter *Interpreter) {
int2 := interpreter.PopInt() int2 := interpreter.PopInt()
int1 := interpreter.PopInt() int1 := interpreter.PopInt()
interpreter.Push(float(int1 % int2)) interpreter.Push(float64(int1 % int2))
} }
//num1 num2 mul product -> Return num1 times num2 //num1 num2 mul product -> Return num1 times num2
@ -51,7 +51,7 @@ func sub(interpreter *Interpreter) {
//num1 abs num2 -> Return absolute value of num1 //num1 abs num2 -> Return absolute value of num1
func abs(interpreter *Interpreter) { func abs(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(math.Fabs(float64(f)))) interpreter.Push(math.Fabs(f))
} }
//num1 neg num2 -> Return negative of num1 //num1 neg num2 -> Return negative of num1
func neg(interpreter *Interpreter) { func neg(interpreter *Interpreter) {
@ -61,63 +61,63 @@ func neg(interpreter *Interpreter) {
//num1 ceiling num2 -> Return ceiling of num1 //num1 ceiling num2 -> Return ceiling of num1
func ceiling(interpreter *Interpreter) { func ceiling(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(int(f + 1))) interpreter.Push(float64(int(f + 1)))
} }
//num1 floor num2 -> Return floor of num1 //num1 floor num2 -> Return floor of num1
func floor(interpreter *Interpreter) { func floor(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(math.Floor(float64(f)))) interpreter.Push(math.Floor(f))
} }
//num1 round num2 -> Round num1 to nearest integer //num1 round num2 -> Round num1 to nearest integer
func round(interpreter *Interpreter) { func round(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(int(f + 0.5))) interpreter.Push(float64(int(f + 0.5)))
} }
//num1 truncate num2 -> Remove fractional part of num1 //num1 truncate num2 -> Remove fractional part of num1
func truncate(interpreter *Interpreter) { func truncate(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(int(f))) interpreter.Push(float64(int(f)))
} }
//num sqrt real -> Return square root of num //num sqrt real -> Return square root of num
func sqrt(interpreter *Interpreter) { func sqrt(interpreter *Interpreter) {
f := interpreter.PopFloat() f := interpreter.PopFloat()
interpreter.Push(float(math.Sqrt(float64(f)))) interpreter.Push(float64(math.Sqrt(f)))
} }
//num den atan angle -> Return arctangent of num/den in degrees //num den atan angle -> Return arctangent of num/den in degrees
func atan(interpreter *Interpreter) { func atan(interpreter *Interpreter) {
den := interpreter.PopFloat() den := interpreter.PopFloat()
num := interpreter.PopFloat() num := interpreter.PopFloat()
interpreter.Push(float(math.Atan2(float64(num), float64(den))) * (180.0 / math.Pi)) interpreter.Push(math.Atan2(num, den) * (180.0 / math.Pi))
} }
//angle cos real -> Return cosine of angle degrees //angle cos real -> Return cosine of angle degrees
func cos(interpreter *Interpreter) { func cos(interpreter *Interpreter) {
a := interpreter.PopFloat() * math.Pi / 180 a := interpreter.PopFloat() * math.Pi / 180
interpreter.Push(float(math.Cos(float64(a )))) interpreter.Push(math.Cos(a))
} }
//angle sin real -> Return sine of angle degrees //angle sin real -> Return sine of angle degrees
func sin(interpreter *Interpreter) { func sin(interpreter *Interpreter) {
a := interpreter.PopFloat() * math.Pi / 180 a := interpreter.PopFloat() * math.Pi / 180
interpreter.Push(float(math.Sin(float64(a)))) interpreter.Push(math.Sin(a))
} }
//base exponent exp real -> Raise base to exponent power //base exponent exp real -> Raise base to exponent power
func exp(interpreter *Interpreter) { func exp(interpreter *Interpreter) {
exponent := interpreter.PopFloat() exponent := interpreter.PopFloat()
base := interpreter.PopFloat() base := interpreter.PopFloat()
interpreter.Push(float(math.Pow(float64(base), float64(exponent)))) interpreter.Push(math.Pow(base, exponent))
} }
//num ln real -> Return natural logarithm (base e) //num ln real -> Return natural logarithm (base e)
func ln(interpreter *Interpreter) { func ln(interpreter *Interpreter) {
num := interpreter.PopFloat() num := interpreter.PopFloat()
interpreter.Push(float(math.Log(float64(num)))) interpreter.Push(math.Log(num))
} }
//num log real -> Return common logarithm (base 10) //num log real -> Return common logarithm (base 10)
func log10(interpreter *Interpreter) { func log10(interpreter *Interpreter) {
num := interpreter.PopFloat() num := interpreter.PopFloat()
interpreter.Push(float(math.Log10(float64(num)))) interpreter.Push(math.Log10(num))
} }
// rand int Generate pseudo-random integer // rand int Generate pseudo-random integer
func randInt(interpreter *Interpreter) { func randInt(interpreter *Interpreter) {
interpreter.Push(float(rand.Int())) interpreter.Push(float64(rand.Int()))
} }
var randGenerator *rand.Rand var randGenerator *rand.Rand
@ -127,7 +127,7 @@ func srand(interpreter *Interpreter) {
} }
// rrand int -> Return random number seed // rrand int -> Return random number seed
func rrand(interpreter *Interpreter) { func rrand(interpreter *Interpreter) {
interpreter.Push(float(randGenerator.Int())) interpreter.Push(float64(randGenerator.Int()))
} }
func initMathOperators(interpreter *Interpreter) { func initMathOperators(interpreter *Interpreter) {

View file

@ -71,7 +71,7 @@ func counttomark(interpreter *Interpreter) {
for _, ok := value.(Mark); !ok; i++ { for _, ok := value.(Mark); !ok; i++ {
value = interpreter.Get(i) value = interpreter.Get(i)
} }
interpreter.Push(float(i)) interpreter.Push(float64(i))
} }
func initStackOperator(interpreter *Interpreter) { func initStackOperator(interpreter *Interpreter) {