/*
* f l o a t . c
* Forth Inspired Command Language
* ANS Forth FLOAT word-set written in C
* Author: Guy Carver & John Sadler (john_sadler@alum.mit.edu)
* Created: Apr 2001
* $Id: float.c,v 1.10 2010/09/13 18:43:04 asau Exp $
*/
/*
* Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
* All rights reserved.
*
* Get the latest Ficl release at http://ficl.sourceforge.net
*
* I am interested in hearing from anyone who uses Ficl. If you have
* a problem, a success story, a defect, an enhancement request, or
* if you would like to contribute to the Ficl release, please
* contact me by email at the address above.
*
* L I C E N S E and D I S C L A I M E R
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "ficl.h"
#if FICL_WANT_FLOAT
#include <math.h>
#include <values.h>
/*
* Create a floating point constant.
* fconstant ( r -"name"- )
*/
static void
{
}
ficlWord *
{
ficlString s;
return (ficlDictionaryAppendConstantInstruction(dictionary, s,
}
ficlWord *
{
ficlString s;
return (ficlDictionarySetConstantInstruction(dictionary, s,
}
static void
{
}
ficlWord *
{
ficlString s;
return (ficlDictionaryAppend2ConstantInstruction(dictionary, s,
}
ficlWord *
{
ficlString s;
return (ficlDictionarySet2ConstantInstruction(dictionary, s,
}
/*
* Display a float in decimal format.
* f. ( r -- )
*/
static void
{
ficlFloat f;
}
/*
* Display a float in engineering format.
* fe. ( r -- )
*/
static void
{
ficlFloat f;
}
/*
* d i s p l a y FS t a c k
* Display the parameter stack (code for "f.s")
* f.s ( -- )
*/
struct stackContext
{
int count;
};
static ficlInteger
{
#ifdef _LP64
#else
#endif
return (FICL_TRUE);
}
void
{
&context);
}
/*
* Do float stack depth.
* fdepth ( -- n )
*/
static void
{
int i;
}
/*
* Compile a floating point literal.
*/
static void
{
if (cell.f == 1.0f) {
} else if (cell.f == 0.0f) {
} else if (cell.f == -1.0f) {
} else {
}
}
/*
* F l o a t P a r s e S t a t e
* Enum to determine the current segement of a floating point number
* being parsed.
*/
typedef enum _floatParseState
{
/*
* f i c l P a r s e F l o a t N u m b e r
* vm -- Virtual Machine pointer.
* s -- String to parse.
* Returns 1 if successful, 0 if not.
*/
int
{
unsigned char c;
unsigned char digit;
char *trace;
char flag = 0;
/*
* floating point numbers only allowed in base 10
*/
return (0);
trace = FICL_STRING_GET_POINTER(s);
length = FICL_STRING_GET_LENGTH(s);
/* Loop through the string's characters. */
switch (estate) {
/* At start of the number so look for a sign. */
case FPS_START:
if (c == '-') {
break;
}
if (c == '+') {
break;
}
/* Note! Drop through to FPS_ININT */
/*
* Converting integer part of number.
* Only allow digits, decimal and 'E'.
*/
case FPS_ININT:
if (c == '.') {
estate = FPS_INMANT;
} else if ((c == 'e') || (c == 'E')) {
} else {
digit = (unsigned char)(c - '0');
if (digit > 9)
return (0);
}
break;
/*
* Processing the fraction part of number.
* Only allow digits and 'E'
*/
case FPS_INMANT:
if ((c == 'e') || (c == 'E')) {
} else {
digit = (unsigned char)(c - '0');
if (digit > 9)
return (0);
mant *= 0.1f;
}
break;
/* Start processing the exponent part of number. */
/* Look for sign. */
case FPS_STARTEXP:
if (c == '-') {
break;
} else if (c == '+') {
break;
}
/* Note! Drop through to FPS_INEXP */
/*
* Processing the exponent part of number.
* Only allow digits.
*/
case FPS_INEXP:
digit = (unsigned char)(c - '0');
if (digit > 9)
return (0);
break;
}
}
/* If parser never made it to the exponent this is not a float. */
if (estate < FPS_STARTEXP)
return (0);
/* Set the sign of the number. */
/* If exponent is not 0 then adjust number by it. */
if (exponent != 0) {
/* Determine if exponent is negative. */
}
/* power = 10^x */
#if defined(_LP64)
#else
#endif
}
return (1);
}
#endif /* FICL_WANT_FLOAT */
#if FICL_WANT_LOCALS
static void
{
}
static void
{
}
#endif /* FICL_WANT_LOCALS */
/*
* Add float words to a system's dictionary.
* system -- Pointer to the Ficl sytem to add float words to.
*/
void
{
#if FICL_WANT_FLOAT
#endif
#if FICL_WANT_LOCALS
#endif /* FICL_WANT_LOCALS */
#if FICL_WANT_FLOAT
/*
* Missing words:
*
* d>f
* f>d
* falign
* faligned
* float+
* floats
* floor
* fmax
* fmin
*/
#if defined(_LP64)
#else
#endif
/* not all required words are present */
#else
#endif
}