remove @TypeOf() hacks for comptime_int/comptime_float

This commit is contained in:
Haze Booth 2020-01-03 19:57:45 -05:00 committed by Andrew Kelley
parent 508a8980ba
commit 2e5342512f
4 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ pub fn ln(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @TypeOf(1.0)(ln_64(x));
return @as(comptime_float, ln_64(x));
},
TypeId.Float => {
return switch (T) {
@ -31,7 +31,7 @@ pub fn ln(x: var) @TypeOf(x) {
};
},
TypeId.ComptimeInt => {
return @TypeOf(1)(math.floor(ln_64(@as(f64, x))));
return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
},
TypeId.Int => {
return @as(T, math.floor(ln_64(@as(f64, x))));

View File

@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
const float_base = math.lossyCast(f64, base);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));
},
TypeId.ComptimeInt => {
return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
},
builtin.TypeId.Int => {
// TODO implement integer log without using float math

View File

@ -22,7 +22,7 @@ pub fn log10(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @TypeOf(1.0)(log10_64(x));
return @as(comptime_float, log10_64(x));
},
TypeId.Float => {
return switch (T) {
@ -32,7 +32,7 @@ pub fn log10(x: var) @TypeOf(x) {
};
},
TypeId.ComptimeInt => {
return @TypeOf(1)(math.floor(log10_64(@as(f64, x))));
return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
},
TypeId.Int => {
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));

View File

@ -22,7 +22,7 @@ pub fn log2(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @TypeOf(1.0)(log2_64(x));
return @as(comptime_float, log2_64(x));
},
TypeId.Float => {
return switch (T) {