rename SomeReal to SomeFloat (#7617)
* rename SomeReal to SomeFloat * added changelog entry
This commit is contained in:
parent
b98cd3bf34
commit
efae366857
6 changed files with 38 additions and 34 deletions
|
|
@ -51,7 +51,10 @@
|
||||||
of the more general ``NimNode``.
|
of the more general ``NimNode``.
|
||||||
- ``macros.getImpl`` now includes the pragmas of types, instead of omitting them.
|
- ``macros.getImpl`` now includes the pragmas of types, instead of omitting them.
|
||||||
- ``macros.hasCustomPragma`` and ``macros.getCustomPragmaVal`` now
|
- ``macros.hasCustomPragma`` and ``macros.getCustomPragmaVal`` now
|
||||||
also support ``ref`` and ``ptr`` types, pragmas on types and variant fields.
|
also support ``ref`` and ``ptr`` types, pragmas on types and variant
|
||||||
|
fields.
|
||||||
|
- ``system.SomeReal`` is now called ``SomeFloat`` for consistency and
|
||||||
|
correctness.
|
||||||
|
|
||||||
### Language additions
|
### Language additions
|
||||||
|
|
||||||
|
|
@ -95,4 +98,3 @@
|
||||||
machine.
|
machine.
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ proc asinh*(m: MathLib, a: SomeNumber): float
|
||||||
proc atan*(m: MathLib, a: SomeNumber): float
|
proc atan*(m: MathLib, a: SomeNumber): float
|
||||||
proc atan2*(m: MathLib, a: SomeNumber): float
|
proc atan2*(m: MathLib, a: SomeNumber): float
|
||||||
proc atanh*(m: MathLib, a: SomeNumber): float
|
proc atanh*(m: MathLib, a: SomeNumber): float
|
||||||
proc cbrt*(m: MathLib, f: SomeReal): SomeReal
|
proc cbrt*(m: MathLib, f: SomeFloat): SomeFloat
|
||||||
proc ceil*(m: MathLib, f: SomeReal): SomeReal
|
proc ceil*(m: MathLib, f: SomeFloat): SomeFloat
|
||||||
proc clz32*(m: MathLib, f: SomeInteger): int
|
proc clz32*(m: MathLib, f: SomeInteger): int
|
||||||
proc cos*(m: MathLib, a: SomeNumber): float
|
proc cos*(m: MathLib, a: SomeNumber): float
|
||||||
proc cosh*(m: MathLib, a: SomeNumber): float
|
proc cosh*(m: MathLib, a: SomeNumber): float
|
||||||
proc exp*(m: MathLib, a: SomeNumber): float
|
proc exp*(m: MathLib, a: SomeNumber): float
|
||||||
proc expm1*(m: MathLib, a: SomeNumber): float
|
proc expm1*(m: MathLib, a: SomeNumber): float
|
||||||
proc floor*(m: MathLib, f: SomeReal): int
|
proc floor*(m: MathLib, f: SomeFloat): int
|
||||||
proc fround*(m: MathLib, f: SomeReal): float32
|
proc fround*(m: MathLib, f: SomeFloat): float32
|
||||||
proc hypot*(m: MathLib, args: varargs[distinct SomeNumber]): float
|
proc hypot*(m: MathLib, args: varargs[distinct SomeNumber]): float
|
||||||
proc imul*(m: MathLib, a, b: int32): int32
|
proc imul*(m: MathLib, a, b: int32): int32
|
||||||
proc log*(m: MathLib, a: SomeNumber): float
|
proc log*(m: MathLib, a: SomeNumber): float
|
||||||
|
|
@ -49,14 +49,14 @@ proc max*(m: MathLib, a, b: SomeNumber): SomeNumber
|
||||||
proc min*[T: SomeNumber | JsRoot](m: MathLib, a, b: T): T
|
proc min*[T: SomeNumber | JsRoot](m: MathLib, a, b: T): T
|
||||||
proc pow*(m: MathLib, a, b: distinct SomeNumber): float
|
proc pow*(m: MathLib, a, b: distinct SomeNumber): float
|
||||||
proc random*(m: MathLib): float
|
proc random*(m: MathLib): float
|
||||||
proc round*(m: MathLib, f: SomeReal): int
|
proc round*(m: MathLib, f: SomeFloat): int
|
||||||
proc sign*(m: MathLib, f: SomeNumber): int
|
proc sign*(m: MathLib, f: SomeNumber): int
|
||||||
proc sin*(m: MathLib, a: SomeNumber): float
|
proc sin*(m: MathLib, a: SomeNumber): float
|
||||||
proc sinh*(m: MathLib, a: SomeNumber): float
|
proc sinh*(m: MathLib, a: SomeNumber): float
|
||||||
proc sqrt*(m: MathLib, f: SomeReal): SomeReal
|
proc sqrt*(m: MathLib, f: SomeFloat): SomeFloat
|
||||||
proc tan*(m: MathLib, a: SomeNumber): float
|
proc tan*(m: MathLib, a: SomeNumber): float
|
||||||
proc tanh*(m: MathLib, a: SomeNumber): float
|
proc tanh*(m: MathLib, a: SomeNumber): float
|
||||||
proc trunc*(m: MathLib, f: SomeReal): int
|
proc trunc*(m: MathLib, f: SomeFloat): int
|
||||||
|
|
||||||
# Date library
|
# Date library
|
||||||
proc now*(d: DateLib): int
|
proc now*(d: DateLib): int
|
||||||
|
|
|
||||||
|
|
@ -26,33 +26,33 @@
|
||||||
|
|
||||||
import typetraits
|
import typetraits
|
||||||
|
|
||||||
proc `+`*[I: SomeInteger, F: SomeReal](i: I, f: F): F {.noSideEffect, inline.} =
|
proc `+`*[I: SomeInteger, F: SomeFloat](i: I, f: F): F {.noSideEffect, inline.} =
|
||||||
F(i) + f
|
F(i) + f
|
||||||
proc `+`*[I: SomeInteger, F: SomeReal](f: F, i: I): F {.noSideEffect, inline.} =
|
proc `+`*[I: SomeInteger, F: SomeFloat](f: F, i: I): F {.noSideEffect, inline.} =
|
||||||
f + F(i)
|
f + F(i)
|
||||||
|
|
||||||
proc `-`*[I: SomeInteger, F: SomeReal](i: I, f: F): F {.noSideEffect, inline.} =
|
proc `-`*[I: SomeInteger, F: SomeFloat](i: I, f: F): F {.noSideEffect, inline.} =
|
||||||
F(i) - f
|
F(i) - f
|
||||||
proc `-`*[I: SomeInteger, F: SomeReal](f: F, i: I): F {.noSideEffect, inline.} =
|
proc `-`*[I: SomeInteger, F: SomeFloat](f: F, i: I): F {.noSideEffect, inline.} =
|
||||||
f - F(i)
|
f - F(i)
|
||||||
|
|
||||||
proc `*`*[I: SomeInteger, F: SomeReal](i: I, f: F): F {.noSideEffect, inline.} =
|
proc `*`*[I: SomeInteger, F: SomeFloat](i: I, f: F): F {.noSideEffect, inline.} =
|
||||||
F(i) * f
|
F(i) * f
|
||||||
proc `*`*[I: SomeInteger, F: SomeReal](f: F, i: I): F {.noSideEffect, inline.} =
|
proc `*`*[I: SomeInteger, F: SomeFloat](f: F, i: I): F {.noSideEffect, inline.} =
|
||||||
f * F(i)
|
f * F(i)
|
||||||
|
|
||||||
proc `/`*[I: SomeInteger, F: SomeReal](i: I, f: F): F {.noSideEffect, inline.} =
|
proc `/`*[I: SomeInteger, F: SomeFloat](i: I, f: F): F {.noSideEffect, inline.} =
|
||||||
F(i) / f
|
F(i) / f
|
||||||
proc `/`*[I: SomeInteger, F: SomeReal](f: F, i: I): F {.noSideEffect, inline.} =
|
proc `/`*[I: SomeInteger, F: SomeFloat](f: F, i: I): F {.noSideEffect, inline.} =
|
||||||
f / F(i)
|
f / F(i)
|
||||||
|
|
||||||
proc `<`*[I: SomeInteger, F: SomeReal](i: I, f: F): bool {.noSideEffect, inline.} =
|
proc `<`*[I: SomeInteger, F: SomeFloat](i: I, f: F): bool {.noSideEffect, inline.} =
|
||||||
F(i) < f
|
F(i) < f
|
||||||
proc `<`*[I: SomeInteger, F: SomeReal](f: F, i: I): bool {.noSideEffect, inline.} =
|
proc `<`*[I: SomeInteger, F: SomeFloat](f: F, i: I): bool {.noSideEffect, inline.} =
|
||||||
f < F(i)
|
f < F(i)
|
||||||
proc `<=`*[I: SomeInteger, F: SomeReal](i: I, f: F): bool {.noSideEffect, inline.} =
|
proc `<=`*[I: SomeInteger, F: SomeFloat](i: I, f: F): bool {.noSideEffect, inline.} =
|
||||||
F(i) <= f
|
F(i) <= f
|
||||||
proc `<=`*[I: SomeInteger, F: SomeReal](f: F, i: I): bool {.noSideEffect, inline.} =
|
proc `<=`*[I: SomeInteger, F: SomeFloat](f: F, i: I): bool {.noSideEffect, inline.} =
|
||||||
f <= F(i)
|
f <= F(i)
|
||||||
|
|
||||||
# Note that we must not defined `>=` and `>`, because system.nim already has a
|
# Note that we must not defined `>=` and `>`, because system.nim already has a
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ type
|
||||||
## ``parseStandardFormatSpecifier`` returned.
|
## ``parseStandardFormatSpecifier`` returned.
|
||||||
|
|
||||||
proc formatInt(n: SomeNumber; radix: int; spec: StandardFormatSpecifier): string =
|
proc formatInt(n: SomeNumber; radix: int; spec: StandardFormatSpecifier): string =
|
||||||
## Converts ``n`` to string. If ``n`` is `SomeReal`, it casts to `int64`.
|
## Converts ``n`` to string. If ``n`` is `SomeFloat`, it casts to `int64`.
|
||||||
## Conversion is done using ``radix``. If result's length is lesser than
|
## Conversion is done using ``radix``. If result's length is lesser than
|
||||||
## ``minimumWidth``, it aligns result to the right or left (depending on ``a``)
|
## ``minimumWidth``, it aligns result to the right or left (depending on ``a``)
|
||||||
## with ``fill`` char.
|
## with ``fill`` char.
|
||||||
|
|
@ -503,8 +503,8 @@ proc format*(value: SomeInteger; specifier: string; res: var string) =
|
||||||
" of 'x', 'X', 'b', 'd', 'o' but got: " & spec.typ)
|
" of 'x', 'X', 'b', 'd', 'o' but got: " & spec.typ)
|
||||||
res.add formatInt(value, radix, spec)
|
res.add formatInt(value, radix, spec)
|
||||||
|
|
||||||
proc format*(value: SomeReal; specifier: string; res: var string) =
|
proc format*(value: SomeFloat; specifier: string; res: var string) =
|
||||||
## Standard format implementation for ``SomeReal``. It makes little
|
## Standard format implementation for ``SomeFloat``. It makes little
|
||||||
## sense to call this directly, but it is required to exist
|
## sense to call this directly, but it is required to exist
|
||||||
## by the ``&`` macro.
|
## by the ``&`` macro.
|
||||||
let spec = parseStandardFormatSpecifier(specifier)
|
let spec = parseStandardFormatSpecifier(specifier)
|
||||||
|
|
@ -678,4 +678,4 @@ when isMainModule:
|
||||||
|
|
||||||
doAssert fmt"{'a'} {'b'}" == "a b"
|
doAssert fmt"{'a'} {'b'}" == "a b"
|
||||||
|
|
||||||
echo("All tests ok")
|
echo("All tests ok")
|
||||||
|
|
|
||||||
|
|
@ -105,12 +105,14 @@ type
|
||||||
## type class matching all ordinal types; however this includes enums with
|
## type class matching all ordinal types; however this includes enums with
|
||||||
## holes.
|
## holes.
|
||||||
|
|
||||||
SomeReal* = float|float32|float64
|
SomeFloat* = float|float32|float64
|
||||||
## type class matching all floating point number types
|
## type class matching all floating point number types
|
||||||
|
|
||||||
SomeNumber* = SomeInteger|SomeReal
|
SomeNumber* = SomeInteger|SomeFloat
|
||||||
## type class matching all number types
|
## type class matching all number types
|
||||||
|
|
||||||
|
{.deprecated: [SomeReal: SomeFloat].}
|
||||||
|
|
||||||
proc defined*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.}
|
proc defined*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.}
|
||||||
## Special compile-time procedure that checks whether `x` is
|
## Special compile-time procedure that checks whether `x` is
|
||||||
## defined.
|
## defined.
|
||||||
|
|
@ -128,7 +130,7 @@ when defined(nimalias):
|
||||||
TSignedInt: SomeSignedInt,
|
TSignedInt: SomeSignedInt,
|
||||||
TUnsignedInt: SomeUnsignedInt,
|
TUnsignedInt: SomeUnsignedInt,
|
||||||
TInteger: SomeInteger,
|
TInteger: SomeInteger,
|
||||||
TReal: SomeReal,
|
TReal: SomeFloat,
|
||||||
TNumber: SomeNumber,
|
TNumber: SomeNumber,
|
||||||
TOrdinal: SomeOrdinal].}
|
TOrdinal: SomeOrdinal].}
|
||||||
|
|
||||||
|
|
@ -2171,8 +2173,8 @@ proc max*[T](x, y: T): T =
|
||||||
if y <= x: x else: y
|
if y <= x: x else: y
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
proc high*(T: typedesc[SomeReal]): T = Inf
|
proc high*(T: typedesc[SomeFloat]): T = Inf
|
||||||
proc low*(T: typedesc[SomeReal]): T = NegInf
|
proc low*(T: typedesc[SomeFloat]): T = NegInf
|
||||||
|
|
||||||
proc clamp*[T](x, a, b: T): T =
|
proc clamp*[T](x, a, b: T): T =
|
||||||
## limits the value ``x`` within the interval [a, b]
|
## limits the value ``x`` within the interval [a, b]
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ proc writeformat(o: var Writer; p: pointer; fmt: Format) =
|
||||||
f.baseprefix = true
|
f.baseprefix = true
|
||||||
writeformat(o, add, cast[uint](p), f)
|
writeformat(o, add, cast[uint](p), f)
|
||||||
|
|
||||||
proc writeformat(o: var Writer; x: SomeReal; fmt: Format) =
|
proc writeformat(o: var Writer; x: SomeFloat; fmt: Format) =
|
||||||
## Write real number `x` according to format `fmt` using output
|
## Write real number `x` according to format `fmt` using output
|
||||||
## object `o` and output function `add`.
|
## object `o` and output function `add`.
|
||||||
var fmt = fmt
|
var fmt = fmt
|
||||||
|
|
@ -401,8 +401,8 @@ proc writeformat(o: var Writer; x: SomeReal; fmt: Format) =
|
||||||
else:
|
else:
|
||||||
len += 4 # exponent
|
len += 4 # exponent
|
||||||
# shift y so that 1 <= abs(y) < 2
|
# shift y so that 1 <= abs(y) < 2
|
||||||
if exp > 0: y /= pow(10.SomeReal, abs(exp).SomeReal)
|
if exp > 0: y /= pow(10.SomeFloat, abs(exp).SomeFloat)
|
||||||
elif exp < 0: y *= pow(10.SomeReal, abs(exp).SomeReal)
|
elif exp < 0: y *= pow(10.SomeFloat, abs(exp).SomeFloat)
|
||||||
elif fmt.typ == ftPercent:
|
elif fmt.typ == ftPercent:
|
||||||
len += 1 # percent sign
|
len += 1 # percent sign
|
||||||
|
|
||||||
|
|
@ -413,7 +413,7 @@ proc writeformat(o: var Writer; x: SomeReal; fmt: Format) =
|
||||||
var mult = 1'i64
|
var mult = 1'i64
|
||||||
for i in 1..prec: mult *= 10
|
for i in 1..prec: mult *= 10
|
||||||
var num = y.int64
|
var num = y.int64
|
||||||
var fr = ((y - num.SomeReal) * mult.SomeReal).int64
|
var fr = ((y - num.SomeFloat) * mult.SomeFloat).int64
|
||||||
# build integer part string
|
# build integer part string
|
||||||
while num != 0:
|
while num != 0:
|
||||||
numstr[numlen] = ('0'.int + (num mod 10)).char
|
numstr[numlen] = ('0'.int + (num mod 10)).char
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue