Skip to content

Commit

Permalink
Add ceil, floor, log10, fmin, fmax
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Mar 4, 2025
1 parent db7584a commit a4e9ac0
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libc/watcom/math/atan.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ _WMRTLINK double _IF_datan( double x )
int sgnx;
double tmp;

#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
if( _RWD_real87 )
return( _atan87(x) );
#endif
Expand Down
42 changes: 42 additions & 0 deletions libc/watcom/math/ceil.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Ceiling routine.
*
****************************************************************************/


#include "variety.h"
#include <math.h>


_WMRTLINK double ceil( double x )
/*******************************/
{
return( -floor( -x ) );
}


2 changes: 1 addition & 1 deletion libc/watcom/math/exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ _WMRTLINK double _IF_dexp( double x )
} else {
x = __math1err( FP_FUNC_EXP | M_OVERFLOW | V_HUGEVAL, &x );
}
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
} else if( _RWD_real87 ) {
x = _exp87( x );
#endif
Expand Down
47 changes: 47 additions & 0 deletions libc/watcom/math/floor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Floating-point floor routine.
*
****************************************************************************/


#include "variety.h"
#include <math.h>


_WMRTLINK double floor( double x )
/********************************/
{
double ipart;
double fraction;

fraction = modf( x, &ipart );
if( fraction < 0.0 ) {
ipart -= 1.0;
}
return( ipart );
}
41 changes: 41 additions & 0 deletions libc/watcom/math/fmax.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 2014 Open Watcom contributors.
* All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Returns the larger of x and y
*
****************************************************************************/

#include "variety.h"
#include <math.h>

_WMRTLINK double fmax(double x, double y)
{
if(x >= y)
return x;
else
return y;
}
41 changes: 41 additions & 0 deletions libc/watcom/math/fmin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 2014 Open Watcom contributors.
* All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Returns the smaller of x and y
*
****************************************************************************/

#include "variety.h"
#include <math.h>

_WMRTLINK double fmin(double x, double y)
{
if(x <= y)
return x;
else
return y;
}
2 changes: 1 addition & 1 deletion libc/watcom/math/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ _WMRTLINK double _IF_dlog( double x )

if( x <= 0.0 ) {
x = __log_matherr( x, FP_FUNC_LOG );
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
} else if( _RWD_real87 ) {
x = _log87( x );
#endif
Expand Down
61 changes: 61 additions & 0 deletions libc/watcom/math/log10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Base 10 logarithm routine.
*
****************************************************************************/


#include "variety.h"
#include "mathlib.h"
#include "ifprag.h"


#define log10_of_e 0.4342944819032518


_WMRTLINK float _IF_log10( float x )
/**********************************/
{
return( _IF_dlog10( x ) );
}

_WMRTLINK double (log10)( double x )
/**********************************/
{
return( _IF_dlog10( x ) );
}

_WMRTLINK double _IF_dlog10( double x )
/*************************************/
{
if( x <= 0.0 ) {
x = __log_matherr( x, FP_FUNC_LOG10 );
} else {
x = log(x) * log10_of_e;
}
return( x );
}
6 changes: 3 additions & 3 deletions libc/watcom/math/sincos.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ _WMRTLINK double (sin)( double x )
_WMRTLINK double _IF_dsin( double x )
/************************/
{
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
if( _RWD_real87 )
return( _sin87(x) );
#endif
Expand All @@ -199,7 +199,7 @@ _WMRTLINK double (cos)( double x )
_WMRTLINK double _IF_dcos( double x )
/***********************************/
{
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
if( _RWD_real87 )
return( _cos87(x) );
#endif
Expand All @@ -223,7 +223,7 @@ _WMRTLINK double (tan)( double x )
_WMRTLINK double _IF_dtan( double x )
/***********************************/
{
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
if( _RWD_real87 )
return( _tan87(x) );
#endif
Expand Down
4 changes: 2 additions & 2 deletions libc/watcom/math/sqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ _WMRTLINK double _IF_dsqrt( double x )
{
if( x < 0.0 ) {
x = __math1err( FP_FUNC_SQRT | M_DOMAIN | V_ZERO, &x );
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
} else if( _RWD_real87 ) {
x = __sqrt87( x );
#endif
} else if( x != 0.0 ) {
#if 0 //defined(_M_IX86)
#if defined(_M_IX86) && 0
x = __sqrtd( x );
#else
int i;
Expand Down

0 comments on commit a4e9ac0

Please sign in to comment.