From c1019d583248c0ffbf85a33cd7eaa232acacfca9 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Thu, 27 Jun 2024 10:58:59 +0200 Subject: [PATCH] Handle INF and NAN in inputs --- kernel/riscv64/scal.c | 5 ++++- kernel/riscv64/scal_vector.c | 4 ++-- kernel/riscv64/zscal.c | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/riscv64/scal.c b/kernel/riscv64/scal.c index 4ef49e2934..6c713aa18c 100644 --- a/kernel/riscv64/scal.c +++ b/kernel/riscv64/scal.c @@ -48,7 +48,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS { if ( da == 0.0 ) - x[i]=0.0; + if (isfinite(x[i])) + x[i]=0.0; + else + x[i]=NAN; else x[i] = da * x[i] ; diff --git a/kernel/riscv64/scal_vector.c b/kernel/riscv64/scal_vector.c index 8fa9315f6b..a1ba41c4f6 100644 --- a/kernel/riscv64/scal_vector.c +++ b/kernel/riscv64/scal_vector.c @@ -71,7 +71,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS FLOAT_V_T v0, v1; unsigned int gvl = 0; if(inc_x == 1){ - if(da == 0.0){ + if (0){ //if(da == 0.0){ memset(&x[0], 0, n * sizeof(FLOAT)); }else{ gvl = VSETVL(n); @@ -96,7 +96,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS } } }else{ - if(da == 0.0){ + if (0) { //if(da == 0.0){ BLASLONG stride_x = inc_x * sizeof(FLOAT); BLASLONG ix = 0; gvl = VSETVL(n); diff --git a/kernel/riscv64/zscal.c b/kernel/riscv64/zscal.c index c4855f73ea..8499145f47 100644 --- a/kernel/riscv64/zscal.c +++ b/kernel/riscv64/zscal.c @@ -61,9 +61,9 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r,FLOAT da_i, F { temp = - da_i * x[ip+1] ; if (isnan(x[ip]) || isinf(x[ip])) temp = NAN; - if (!isinf(x[ip+1])) + if (!isinf(x[ip+1])) x[ip+1] = da_i * x[ip] ; - else x[ip+1] = NAN; + else x[ip+1] = NAN; } } else