mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
float64 is now an alias to 'float'; fixes #545
This commit is contained in:
@@ -465,10 +465,11 @@ proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||
proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
const
|
||||
binArithTab: array[mAddF64..mXor, string] = [
|
||||
"($1 + $2)", # AddF64
|
||||
"($1 - $2)", # SubF64
|
||||
"($1 * $2)", # MulF64
|
||||
"($1 / $2)", # DivF64
|
||||
"(($4)($1) + ($4)($2))", # AddF64
|
||||
"(($4)($1) - ($4)($2))", # SubF64
|
||||
"(($4)($1) * ($4)($2))", # MulF64
|
||||
"(($4)($1) / ($4)($2))", # DivF64
|
||||
|
||||
"($4)((NU$3)($1) >> (NU$3)($2))", # ShrI
|
||||
"($4)((NU$3)($1) << (NU$3)($2))", # ShlI
|
||||
"($4)($1 & $2)", # BitandI
|
||||
@@ -1488,8 +1489,9 @@ proc binaryFloatArith(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||
assert(e.sons[2].typ != nil)
|
||||
InitLocExpr(p, e.sons[1], a)
|
||||
InitLocExpr(p, e.sons[2], b)
|
||||
putIntoDest(p, d, e.typ, rfmt(nil, "($2 $1 $3)",
|
||||
toRope(opr[m]), rdLoc(a), rdLoc(b)))
|
||||
putIntoDest(p, d, e.typ, rfmt(nil, "(($4)($2) $1 ($4)($3))",
|
||||
toRope(opr[m]), rdLoc(a), rdLoc(b),
|
||||
getSimpleTypeDesc(p.module, e[1].typ)))
|
||||
if optNanCheck in p.options:
|
||||
linefmt(p, cpsStmts, "#nanCheck($1);$n", rdLoc(d))
|
||||
if optInfCheck in p.options:
|
||||
|
||||
@@ -115,11 +115,16 @@ proc getIntLitType*(literal: PNode): PType =
|
||||
result = copyType(ti, ti.owner, false)
|
||||
result.n = literal
|
||||
|
||||
proc getFloatLitType*(literal: PNode): PType =
|
||||
# for now we do not cache these:
|
||||
result = newSysType(tyFloat, size=8)
|
||||
result.n = literal
|
||||
|
||||
proc skipIntLit*(t: PType): PType {.inline.} =
|
||||
if t.kind == tyInt and t.n != nil:
|
||||
result = getSysType(tyInt)
|
||||
else:
|
||||
result = t
|
||||
if t.n != nil:
|
||||
if t.kind in {tyInt, tyFloat}:
|
||||
return getSysType(t.kind)
|
||||
result = t
|
||||
|
||||
proc AddSonSkipIntLit*(father, son: PType) =
|
||||
if isNil(father.sons): father.sons = @[]
|
||||
|
||||
@@ -1808,7 +1808,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||
of nkUInt64Lit:
|
||||
if result.typ == nil: result.typ = getSysType(tyUInt64)
|
||||
of nkFloatLit:
|
||||
if result.typ == nil: result.typ = getSysType(tyFloat)
|
||||
if result.typ == nil: result.typ = getFloatLitType(result)
|
||||
of nkFloat32Lit:
|
||||
if result.typ == nil: result.typ = getSysType(tyFloat32)
|
||||
of nkFloat64Lit:
|
||||
|
||||
@@ -21,7 +21,7 @@ proc getConstExpr*(m: PSym, n: PNode): PNode
|
||||
proc evalOp*(m: TMagic, n, a, b, c: PNode): PNode
|
||||
proc leValueConv*(a, b: PNode): bool
|
||||
proc newIntNodeT*(intVal: BiggestInt, n: PNode): PNode
|
||||
proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode): PNode
|
||||
proc newFloatNodeT(floatVal: BiggestFloat, n: PNode): PNode
|
||||
proc newStrNodeT*(strVal: string, n: PNode): PNode
|
||||
|
||||
# implementation
|
||||
@@ -43,7 +43,10 @@ proc newIntNodeT(intVal: BiggestInt, n: PNode): PNode =
|
||||
|
||||
proc newFloatNodeT(floatVal: BiggestFloat, n: PNode): PNode =
|
||||
result = newFloatNode(nkFloatLit, floatVal)
|
||||
result.typ = n.typ
|
||||
if skipTypes(n.typ, abstractVarRange).kind == tyFloat:
|
||||
result.typ = getFloatLitType(result)
|
||||
else:
|
||||
result.typ = n.typ
|
||||
result.info = n.info
|
||||
|
||||
proc newStrNodeT(strVal: string, n: PNode): PNode =
|
||||
|
||||
@@ -283,14 +283,18 @@ proc isConvertibleToRange(f, a: PType): bool =
|
||||
a.kind in {tyFloat..tyFloat128}:
|
||||
result = true
|
||||
|
||||
proc handleFloatRange(f, a: PType): TTypeRelation =
|
||||
if a.kind == f.kind:
|
||||
proc handleFloatRange(f, a: PType): TTypeRelation =
|
||||
if a.kind == f.kind:
|
||||
result = isEqual
|
||||
else:
|
||||
else:
|
||||
let ab = skipTypes(a, {tyRange})
|
||||
var k = ab.kind
|
||||
if k == f.kind: result = isSubrange
|
||||
elif isFloatLit(ab): result = isFromIntLit
|
||||
elif isIntLit(ab): result = isConvertible
|
||||
elif f.kind == tyFloat32:
|
||||
# no conversion to "float32" as that might lose precision
|
||||
result = isNone
|
||||
elif k >= tyFloat and k <= tyFloat128: result = isConvertible
|
||||
else: result = isNone
|
||||
|
||||
|
||||
@@ -109,6 +109,9 @@ proc getOrdValue(n: PNode): biggestInt =
|
||||
proc isIntLit*(t: PType): bool {.inline.} =
|
||||
result = t.kind == tyInt and t.n != nil and t.n.kind == nkIntLit
|
||||
|
||||
proc isFloatLit*(t: PType): bool {.inline.} =
|
||||
result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit
|
||||
|
||||
proc isCompatibleToCString(a: PType): bool =
|
||||
if a.kind == tyArray:
|
||||
if (firstOrd(a.sons[0]) == 0) and
|
||||
|
||||
@@ -28,7 +28,9 @@ type
|
||||
uint64* {.magic: UInt64.} ## unsigned 64 bit integer type
|
||||
float* {.magic: Float.} ## default floating point type
|
||||
float32* {.magic: Float32.} ## 32 bit floating point type
|
||||
float64* {.magic: Float64.} ## 64 bit floating point type
|
||||
float64* {.magic: Float.} ## 64 bit floating point type
|
||||
|
||||
# 'float64' is now an alias to 'float'; this solves many problems
|
||||
|
||||
type # we need to start a new type section here, so that ``0`` can have a type
|
||||
bool* {.magic: Bool.} = enum ## built-in boolean type
|
||||
@@ -627,6 +629,14 @@ proc `<%` *(x, y: Int64): bool {.magic: "LtU64", noSideEffect.}
|
||||
|
||||
|
||||
# floating point operations:
|
||||
|
||||
proc `+` *(x: float32): float32 {.magic: "UnaryPlusF64", noSideEffect.}
|
||||
proc `-` *(x: float32): float32 {.magic: "UnaryMinusF64", noSideEffect.}
|
||||
proc `+` *(x, y: float32): float32 {.magic: "AddF64", noSideEffect.}
|
||||
proc `-` *(x, y: float32): float32 {.magic: "SubF64", noSideEffect.}
|
||||
proc `*` *(x, y: float32): float32 {.magic: "MulF64", noSideEffect.}
|
||||
proc `/` *(x, y: float32): float32 {.magic: "DivF64", noSideEffect.}
|
||||
|
||||
proc `+` *(x: float): float {.magic: "UnaryPlusF64", noSideEffect.}
|
||||
proc `-` *(x: float): float {.magic: "UnaryMinusF64", noSideEffect.}
|
||||
proc `+` *(x, y: float): float {.magic: "AddF64", noSideEffect.}
|
||||
@@ -635,6 +645,10 @@ proc `*` *(x, y: float): float {.magic: "MulF64", noSideEffect.}
|
||||
proc `/` *(x, y: float): float {.magic: "DivF64", noSideEffect.}
|
||||
## computes the floating point division
|
||||
|
||||
proc `==` *(x, y: float32): bool {.magic: "EqF64", noSideEffect.}
|
||||
proc `<=` *(x, y: float32): bool {.magic: "LeF64", noSideEffect.}
|
||||
proc `<` *(x, y: float32): bool {.magic: "LtF64", noSideEffect.}
|
||||
|
||||
proc `==` *(x, y: float): bool {.magic: "EqF64", noSideEffect.}
|
||||
proc `<=` *(x, y: float): bool {.magic: "LeF64", noSideEffect.}
|
||||
proc `<` *(x, y: float): bool {.magic: "LtF64", noSideEffect.}
|
||||
@@ -1985,7 +1999,7 @@ when not defined(JS): #and not defined(NimrodVM):
|
||||
## `content` completely to the file and closes the file afterwards.
|
||||
## Raises an IO exception in case of an error.
|
||||
|
||||
proc write*(f: TFile, r: float) {.tags: [FWriteIO].}
|
||||
proc write*(f: TFile, r: float32) {.tags: [FWriteIO].}
|
||||
proc write*(f: TFile, i: int) {.tags: [FWriteIO].}
|
||||
proc write*(f: TFile, i: biggestInt) {.tags: [FWriteIO].}
|
||||
proc write*(f: TFile, r: biggestFloat) {.tags: [FWriteIO].}
|
||||
|
||||
@@ -91,7 +91,7 @@ proc write(f: TFile, i: biggestInt) =
|
||||
proc write(f: TFile, b: bool) =
|
||||
if b: write(f, "true")
|
||||
else: write(f, "false")
|
||||
proc write(f: TFile, r: float) = fprintf(f, "%g", r)
|
||||
proc write(f: TFile, r: float32) = fprintf(f, "%g", r)
|
||||
proc write(f: TFile, r: biggestFloat) = fprintf(f, "%g", r)
|
||||
|
||||
proc write(f: TFile, c: Char) = putc(c, f)
|
||||
|
||||
Reference in New Issue
Block a user