1
0
Fork 0
Little S-Expression Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sxpf/number.go

49 lines
1.3 KiB

//-----------------------------------------------------------------------------
// Copyright (c) 2022 Detlef Stern
//
// This file is part of sxpf.
//
// sxpf is licensed under the latest version of the EUPL // (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------
package sxpf
import (
"io"
"strconv"
)
// Integer value store integer numbers.
type Integer struct {
val int64
}
// NewInteger create a new integer value.
func NewInteger(i int64) *Integer { return &Integer{val: i} }
// GetValue returns the integer value.
func (i *Integer) GetValue() int64 { return i.val }
func (i *Integer) IsNil() bool { return i == nil }
// Equal returns true if the other value is equal to this one.
func (i *Integer) Equal(other Value) bool {
if i == nil || IsNil(other) {
return i == other
}
if o, ok := other.(*Integer); ok {
return i.val == o.val
}
return false
}
func (i *Integer) Print(w io.Writer) error {
_, err := io.WriteString(w, strconv.FormatInt(i.val, 10))
return err
}
func (i *Integer) Value() string { return strconv.FormatInt(i.val, 10) }
func (i *Integer) String() string { return strconv.FormatInt(i.val, 10) }