Initial commit

This commit is contained in:
2025-08-20 19:02:58 +08:00
commit f6b2677c0f
8577 changed files with 1307117 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
LIST=ALL
EARLY_DIRS=lib
LATE_DIRS=apps mme
include recurse.mk

25
README.md Normal file
View File

@@ -0,0 +1,25 @@
# QNX Neutrino源代码
欢迎来到QNX Neutrino源代码下载仓库。本仓库致力于提供QNX操作系统的核心源代码这些代码是从官方SVN库中直接拉取的旨在为嵌入式系统开发者、操作系统爱好者以及技术研究者提供一个便捷的学习和参考平台。
**QNX Neutrino简介**
QNX Neutrino是一款高度可靠、实时的操作系统广泛应用于汽车电子、工业自动化、医疗设备、航空航天等多个领域。其微内核架构是其一大特色提供了卓越的稳定性和安全性。通过学习QNX Neutrino的源代码开发者可以深入理解实时操作系统的内部工作机制包括进程管理、内存管理、网络协议栈等关键组件的设计与实现。
**仓库内容:**
- 本仓库包含QNX Neutrino操作系统的官方源代码。
- 源代码覆盖了内核、驱动程序、系统服务等多个方面的内容。
- 注意,由于版权和许可限制,请在合法范围内使用这些资源进行学习和研究。
**如何使用:**
1. **获取代码**首先确保你有适当的开发环境推荐使用支持版本控制的IDE或命令行工具。
2. **编译与构建**下载源码后参照QNX官方文档设置你的开发环境并进行编译。QNX Development Suite是首选的开发工具。
3. **学习与探索**利用源码阅读工具或IDE的特性来浏览和学习代码结构。理解每个模块的功能和它们之间的交互。
4. **遵守许可证**:在进行任何二次开发前,请详细阅读并遵守随源代码提供的许可证条款。
**贡献与反馈:**
- 由于这是仅供学习的资源集合,仓库主要目的是分享,不直接接收代码贡献。
- 对于学习过程中的疑问或发现的技术点建议查阅QNX官方论坛或社区进行讨论。
请注意实际应用中使用QNX系统及源代码时应遵循QNX Software Systems有限公司的最新许可规定。此资源仅供学习和研究目的请勿用于商业用途未经适当授权。
加入我们的行列深化对实时操作系统领域的理解探索QNX Neutrino的强大功能与精妙设计。祝你在学习之旅中收获满满

4
lib/Makefile Normal file
View File

@@ -0,0 +1,4 @@
LIST=LIB
EARLY_DIRS=c m compat qnx socket tar z expat
LATE_DIRS=squrl gri mesa imaging pkgdiff package mmedia
include recurse.mk

2
lib/asyncmsg/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=CPU
include recurse.mk

View File

@@ -0,0 +1,107 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include "asyncmsg_priv.h"
#define _ASYNCMSG_HANDLE_LIST_GROW 4
struct _asyncmsg_handle_list {
pthread_rwlock_t rwlock;
void **array;
int array_total;
};
static struct _asyncmsg_handle_list _channel_list = {
PTHREAD_RWLOCK_INITIALIZER, 0, 0
};
static struct _asyncmsg_handle_list _fd_list = {
PTHREAD_RWLOCK_INITIALIZER, 0, 0
};
static struct _asyncmsg_handle_list _connect_list = {
PTHREAD_RWLOCK_INITIALIZER, 0, 0
};
void * _asyncmsg_handle(int id, int cmd, void *handle)
{
struct _asyncmsg_handle_list *list;
if (cmd & _ASYNCMSG_HANDLE_CHANNEL) {
cmd &= ~_ASYNCMSG_HANDLE_CHANNEL;
list = &_channel_list;
} else if (id & _NTO_SIDE_CHANNEL) {
list = &_connect_list;
id &= ~_NTO_SIDE_CHANNEL;
} else {
list = &_fd_list;
}
if (cmd == _ASYNCMSG_HANDLE_ADD) {
if ((errno = pthread_rwlock_wrlock(&list->rwlock)) != EOK) {
return NULL;
}
if (list->array_total <= id) {
void **new_array;
size_t new_size;
int extra;
if ((extra = id - list->array_total + 1) < _ASYNCMSG_HANDLE_LIST_GROW)
extra = _ASYNCMSG_HANDLE_LIST_GROW;
new_size = (list->array_total + extra) * sizeof(void *);
if ((new_array = realloc(list->array, new_size)) == NULL) {
pthread_rwlock_unlock(&list->rwlock);
return NULL;
}
memset(&new_array[list->array_total], 0, extra * sizeof(void *));
list->array = new_array;
list->array_total += extra;
}
list->array[id] = handle;
pthread_rwlock_unlock(&list->rwlock);
return handle;
}
if (id >= list->array_total) {
errno = ESRCH;
return NULL;
}
if ((errno = pthread_rwlock_rdlock(&list->rwlock)) != EOK) {
return NULL;
}
handle = list->array[id];
if (cmd & _ASYNCMSG_HANDLE_DELETE) {
list->array[id] = NULL;
}
pthread_rwlock_unlock(&list->rwlock);
if (!handle)
errno = ESRCH;
return handle;
}
__SRCVERSION("_asyncmsg_handle.c $Rev: 157149 $");

View File

@@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1,69 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <errno.h>
#include <stdlib.h>
#include "asyncmsg_priv.h"
/* This is painful. We have to prepare receive buf, and associate
* it with the chid, so we will know where to receive
*/
int asyncmsg_channel_create(unsigned flags, mode_t mode, size_t buffer_size, unsigned max_num_buffer, const struct sigevent *ev, int (*recvbuf_callback)(size_t bufsize, unsigned num_bufs, void*bufs[], int flags))
{
struct _asyncmsg_channel_context *acc;
int chid;
if ((acc = (struct _asyncmsg_channel_context *)malloc(sizeof(*acc))) == NULL) {
return -1;
}
memset(acc, 0, sizeof(*acc));
if ((errno = pthread_mutex_init(&acc->mutex, 0)) != EOK) {
free(acc);
return -1;
}
acc->recvbuf_cb = recvbuf_callback;
acc->max_num_buffer = max_num_buffer;
acc->buffer_size = buffer_size;
if ((acc->iovs = malloc(sizeof(iov_t) * max_num_buffer)) == NULL) {
free(acc);
return -1;
}
if ((chid = ChannelCreateExt(flags | _NTO_CHF_ASYNC, mode, buffer_size, max_num_buffer, ev, NULL)) == -1) {
pthread_mutex_destroy(&acc->mutex);
free(acc->iovs);
free(acc);
return -1;
}
if (_asyncmsg_handle(chid, _ASYNCMSG_HANDLE_ADD | _ASYNCMSG_HANDLE_CHANNEL, acc) == NULL) {
asyncmsg_channel_destroy(chid);
free(acc->iovs);
free(acc);
return -1;
}
return chid;
}
__SRCVERSION("asyncmsg_channel_create.c $Rev: 153052 $");

View File

@@ -0,0 +1,75 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdlib.h>
#include "asyncmsg_priv.h"
int asyncmsg_channel_destroy(int chid)
{
struct _asyncmsg_channel_context *acc;
if (ChannelDestroy(chid) == -1) {
return -1;
}
if ((acc = _asyncmsg_handle(chid, _ASYNCMSG_HANDLE_DELETE | _ASYNCMSG_HANDLE_CHANNEL, 0)) == NULL)
{
return -1;
}
/* how do we destroy mutex safely ? */
pthread_mutex_destroy(&acc->mutex);
if (acc->free) {
if (!acc->recvbuf_cb) {
struct _asyncmsg_get_header *ahp;
while (ahp = acc->free) {
acc->free = ahp->next;
asyncmsg_free(ahp);
}
} else {
int i, n;
void **buffs, *single_buf;
if ((buffs = alloca(acc->num_free * sizeof(void *))) == NULL) {
buffs = &single_buf;
n = 1;
} else {
n = acc->num_free;
}
do {
for (i = 0; i < n; i++) {
buffs[i] = acc->free;
acc->free = acc->free->next;
}
acc->recvbuf_cb(acc->buffer_size + sizeof(iov_t) + sizeof(struct _asyncmsg_get_header),
n, buffs, ASYNCMSG_RECVBUF_FREE);
acc->num_free -= n;
} while (acc->num_free);
}
}
free(acc->iovs);
free(acc);
return 0;
}
__SRCVERSION("asyncmsg_channel_destroy.c $Rev: 153052 $");

View File

@@ -0,0 +1,181 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/mman.h>
#include "asyncmsg_priv.h"
static struct sigevent *_async_ev;
static pthread_t _async_ev_tid;
static void * _async_event_thread(void *arg)
{
int chid = (int)arg, coid;
struct _pulse pulse;
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
for (;;) {
if (MsgReceivePulse(chid, &pulse, sizeof(pulse), NULL) == -1)
return NULL;
coid = pulse.value.sival_int;
if ((acc = _asyncmsg_handle(coid, _ASYNCMSG_HANDLE_LOOKUP, 0)) == NULL)
continue;
acd = &acc->acd;
_mutex_lock(&acd->mu);
if (pulse.code == 'T') {
/* triger timer expired */
if (acc->acd.num_curmsg) {
MsgSendAsync(coid);
}
acc->flags |= _ASYNCMSG_CONNECT_TIMEROFF;
_mutex_unlock(&acd->mu);
continue;
}
if (pulse.code == 'P')
{
/* collect some done message from "free" ptr */
struct _asyncmsg_put_header *aph;
while (acd->sendq_free != acd->sendq_head) {
aph = &acd->sendq[acd->sendq_free];
if (aph->cb) {
aph->cb(aph->err, aph->iov, aph->handle);
} else if (acd->attr.call_back) {
acd->attr.call_back(aph->err, aph->iov, aph->handle);
}
if (++acd->sendq_free >= acd->sendq_size)
acd->sendq_free = 0;
}
/* Sigh! have to use broadcast cause the condvar both
* use for queue full, and asyncmsg_flush()
*/
pthread_cond_broadcast(&acd->block_con);
_mutex_unlock(&acd->mu);
}
}
}
int asyncmsg_connect_attach(uint32_t nd, pid_t pid, int chid, unsigned index, unsigned flags, const struct _asyncmsg_connection_attr *attr)
{
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
int id, size;
static pthread_mutex_t _async_init_mutex = PTHREAD_MUTEX_INITIALIZER;
_mutex_lock(&_async_init_mutex);
if (!_async_ev) {
int chid;
if ((_async_ev = malloc(sizeof(*_async_ev))) == NULL) {
_mutex_unlock(&_async_init_mutex);
return -1;
}
if ((chid = ChannelCreate(0)) == -1)
{
free(_async_ev);
_async_ev = NULL;
_mutex_unlock(&_async_init_mutex);
return -1;
}
if ((_async_ev->sigev_coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1)
{
ChannelDestroy(chid);
free(_async_ev);
_async_ev = NULL;
_mutex_unlock(&_async_init_mutex);
return -1;
}
_async_ev->sigev_notify = SIGEV_PULSE;
_async_ev->sigev_priority = SIGEV_PULSE_PRIO_INHERIT;
if ((errno = pthread_create(&_async_ev_tid, NULL, _async_event_thread, (void *)chid)) != EOK)
{
ConnectDetach(_async_ev->sigev_coid);
ChannelDestroy(chid);
free(_async_ev);
_async_ev = NULL;
_mutex_unlock(&_async_init_mutex);
return -1;
}
}
_mutex_unlock(&_async_init_mutex);
size = sizeof(*acc) + sizeof(struct _asyncmsg_put_header) * attr->max_num_buffer;
acc = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_PHYS, NOFD, 0);
if (acc == (struct _asyncmsg_connect_context *)MAP_FAILED) {
return -1;
}
memset(acc, 0, sizeof(*acc));
acd = &acc->acd;
flags |= _NTO_COF_NOSHARE;
acd->attr = *attr;
acd->flags = flags;
acd->sendq_size = attr->max_num_buffer;
acd->sendq = (struct _asyncmsg_put_header *)((char *)acc + sizeof(*acc));
if ((id = ConnectAttachExt(nd, pid, chid, index, flags, acd)) == -1) {
return -1;
}
acd->sendq_head = acd->sendq_tail = acd->sendq_free = 0;
acd->ev = *_async_ev;
acd->ev.sigev_value.sival_int = id;
acd->ev.sigev_code = 'T';
if ((acd->ttimer = TimerCreate(CLOCK_REALTIME, &acd->ev)) == (timer_t)-1) {
asyncmsg_connect_detach(id);
return -1;
}
acc->flags = _ASYNCMSG_CONNECT_TIMEROFF;
acd->ev.sigev_code = 'P';
if ((errno = pthread_mutex_init(&acd->mu, 0)) != EOK)
{
asyncmsg_connect_detach(id);
return -1;
}
if ((errno = pthread_cond_init(&acd->block_con, 0)) != EOK)
{
asyncmsg_connect_detach(id);
return -1;
}
if (_asyncmsg_handle(id, _ASYNCMSG_HANDLE_ADD, acc) == NULL) {
asyncmsg_connect_detach(id);
return -1;
}
return id;
}
__SRCVERSION("asyncmsg_connect_attach.c $Rev: 153052 $");

View File

@@ -0,0 +1,48 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include "asyncmsg_priv.h"
int asyncmsg_connect_attr(int coid, struct _asyncmsg_connection_attr *old_attr, const struct _asyncmsg_connection_attr *new_attr)
{
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
if ((acc = _asyncmsg_handle(coid, _ASYNCMSG_HANDLE_LOOKUP, 0)) == NULL)
return -1;
acd = &acc->acd;
_mutex_lock(&acd->mu);
if (old_attr) {
*old_attr = acd->attr;
}
if (new_attr) {
acd->attr = *new_attr;
/* I can't change max_buffer_size/buff_size, these
* will causing acd->start changed, which means, the
* memory kernel is referencing will gone :-(
*/
}
_mutex_unlock(&acd->mu);
return 0;
}
__SRCVERSION("asyncmsg_connect_attr.c $Rev: 153052 $");

View File

@@ -0,0 +1,79 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#include "asyncmsg_priv.h"
int asyncmsg_connect_detach(int coid)
{
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
struct _asyncmsg_put_header *aph;
if (ConnectDetach(coid) == -1)
return -1;
if ((acc = _asyncmsg_handle(coid, _ASYNCMSG_HANDLE_DELETE, 0)) == NULL)
return -1;
timer_delete(acc->acd.ttimer);
/* if there is still message in the queue, remove them. The q is like:
*
* (free slot we know) --- (kernel point here) --- (lib point here)
* free head tail
*
* free to head are already processed by kernel,
* head to tail are messages already aysncmsg_put() but not processed,
* tail to free are free slot for further asyncmsg_put().
*/
acd = &acc->acd;
_mutex_lock(&acd->mu);
while (acd->sendq_free != acd->sendq_tail) {
aph = &acd->sendq[acd->sendq_free];
/* cast to int to protect wrap over */
if ((int)(acd->sendq_free - acd->sendq_head) >= 0) {
aph->err = EBADF;
}
if (aph->cb) {
aph->cb(aph->err, aph->iov, aph->handle);
} else if (acd->attr.call_back) {
acd->attr.call_back(aph->err, aph->iov, aph->handle);
}
if (++acd->sendq_free >= acd->sendq_size)
acd->sendq_free = 0;
}
/* Sigh! have to use broadcast cause the condvar both
* use for queue full, and asyncmsg_flush()
*/
pthread_cond_broadcast(&acd->block_con);
_mutex_unlock(&acd->mu);
pthread_cond_destroy(&acc->acd.block_con);
pthread_mutex_destroy(&acc->acd.mu);
munmap(acc, sizeof(*acc));
return 0;
}
__SRCVERSION("asyncmsg_connect_detach.c $Rev: 153052 $");

View File

@@ -0,0 +1,46 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include "asyncmsg_priv.h"
int asyncmsg_flush(int coid, int mode)
{
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
int ret;
ret = MsgSendAsync(coid);
if (ret == -1 || mode == ASYNCMSG_FLUSH_NONBLOCK)
return ret;
if ((acc = _asyncmsg_handle(coid, _ASYNCMSG_HANDLE_LOOKUP, 0)) == NULL)
return -1;
acd = &acc->acd;
_mutex_lock(&acd->mu);
while (acd->num_curmsg) {
pthread_cond_wait(&acd->block_con, &acd->mu);
}
_mutex_unlock(&acd->mu);
return 0;
}
__SRCVERSION("asyncmsg_flush.c $Rev: 153052 $");

View File

@@ -0,0 +1,30 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdlib.h>
#include <sys/asyncmsg.h>
void asyncmsg_free(void *buf)
{
free(buf);
return;
}
__SRCVERSION("asyncmsg_free.c $Rev: 153052 $");

116
lib/asyncmsg/asyncmsg_get.c Normal file
View File

@@ -0,0 +1,116 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <unistd.h>
#include "asyncmsg_priv.h"
struct _asyncmsg_get_header* asyncmsg_get(int chid)
{
struct _asyncmsg_get_header *agh;
struct _asyncmsg_channel_context *acc;
iov_t *iov;
size_t entsize;
int n, used;
if ((acc = _asyncmsg_handle(chid, _ASYNCMSG_HANDLE_LOOKUP | _ASYNCMSG_HANDLE_CHANNEL, 0)) == NULL)
return NULL;
entsize = sizeof(struct _asyncmsg_get_header) + sizeof(iov_t) + acc->buffer_size;
_mutex_lock(&acc->mutex);
while (acc->num_free < acc->max_num_buffer) {
void *bufs[1];
if (!acc->recvbuf_cb) {
if ((agh = asyncmsg_malloc(entsize)) == NULL) {
break;
}
memset(agh, 0, entsize);
agh->iov = (iov_t *)(agh + 1);
agh->iov->iov_base = agh->iov + 1;
agh->iov->iov_len = acc->buffer_size;
agh->parts = 1;
agh->next = acc->free;
acc->free = agh;
acc->num_free++;
} else {
if (acc->recvbuf_cb(entsize, 1, (void **)bufs, ASYNCMSG_RECVBUF_ALLOC) <= 0) {
break;
}
agh = bufs[0];
memset(agh, 0, entsize);
agh->iov = (iov_t *)(agh + 1);
agh->iov->iov_base = agh->iov + 1;
agh->iov->iov_len = acc->buffer_size;
agh->parts = 1;
agh->next = acc->free;
acc->free = agh;
acc->num_free++;
}
}
iov = acc->iovs;
for (n = 0, agh = acc->free; n < acc->max_num_buffer && agh; n++, agh = agh->next)
{
SETIOV(&iov[n], agh, entsize);
}
if (n == 0) {
_mutex_unlock(&acc->mutex);
return NULL;
}
if (agh) {
acc->free = agh;
agh = iov[n - 1].iov_base;
agh->next = NULL;
} else {
acc->free = NULL;
}
acc->num_free -= n;
_mutex_unlock(&acc->mutex);
if ((used = MsgReceiveAsync(chid, iov, n)) <= 0) {
_mutex_lock(&acc->mutex);
agh = iov[n - 1].iov_base;
agh->next = acc->free;
acc->free = iov[0].iov_base;
acc->num_free += n;
_mutex_unlock(&acc->mutex);
return NULL;
}
if (used < n) {
_mutex_lock(&acc->mutex);
agh = iov[n - 1].iov_base;
agh->next = acc->free;
acc->free = iov[used].iov_base;
agh = iov[used - 1].iov_base;
agh->next = NULL;
acc->num_free += n - used;
_mutex_unlock(&acc->mutex);
}
agh = iov[0].iov_base;
return agh;
}
__SRCVERSION("asyncmsg_get.c $Rev: 157149 $");

View File

@@ -0,0 +1,29 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdlib.h>
#include <sys/asyncmsg.h>
void *asyncmsg_malloc(size_t size)
{
return malloc(size);
}
__SRCVERSION("asyncmsg_malloc.c $Rev: 153052 $");

View File

@@ -0,0 +1,59 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#ifndef _ASYNCMSG_PRIV_H_INCLUDED
#define _ASYNCMSG_PRIV_H_INCLUDED
#ifndef _ASYNCMSG_H_INCLUDED
#include <sys/asyncmsg.h>
#endif
#ifndef _STRING_H_INCLUDE
#include <string.h>
#endif
struct _asyncmsg_channel_context {
pthread_mutex_t mutex;
int (*recvbuf_cb)(size_t bufsize, unsigned num_bufs, void*bufs[], int flags);
int buffer_size;
int max_num_buffer;
struct _asyncmsg_get_header *free;
int num_free;
iov_t *iovs;
};
struct _asyncmsg_connect_context {
unsigned flags;
struct _asyncmsg_connection_descriptor acd;
};
#define _ASYNCMSG_CONNECT_TIMEROFF 1
/* by default, every get will try to receive 5 message */
#define _ASYNCMSG_DEFAULT_GET 5
/* for _asyncmsg_handle */
#define _ASYNCMSG_HANDLE_ADD 0
#define _ASYNCMSG_HANDLE_LOOKUP 1
#define _ASYNCMSG_HANDLE_DELETE 2
#define _ASYNCMSG_HANDLE_CHANNEL 0x80000000
extern void * _asyncmsg_handle(int id, int cmd, void *handle);
#endif

View File

@@ -0,0 +1,92 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <errno.h>
#include "asyncmsg_priv.h"
static int _asyncmsg_put_trigger(int coid, struct _asyncmsg_connect_context *acc)
{
/* figure out if we need to trigger kernel */
acc->acd.num_curmsg++;
if (acc->acd.attr.trigger_num_msg && acc->acd.num_curmsg >= acc->acd.attr.trigger_num_msg)
{
return MsgSendAsync(coid);
}
/* if this is the first message, trigger & tick the ttimer */
if (acc->flags & _ASYNCMSG_CONNECT_TIMEROFF) {
TimerSettime(acc->acd.ttimer, 0, &acc->acd.attr.trigger_time, NULL);
acc->flags &= ~_ASYNCMSG_CONNECT_TIMEROFF;
}
return 0;
}
int asyncmsg_putv(int coid, const iov_t* iov, int parts, unsigned handle, int (*call_back)(int err, void* buf, unsigned handle))
{
struct _asyncmsg_connect_context *acc;
struct _asyncmsg_connection_descriptor *acd;
struct _asyncmsg_put_header *aph;
unsigned new_tail;
int err;
if ((acc = _asyncmsg_handle(coid, _ASYNCMSG_HANDLE_LOOKUP, 0)) == NULL)
return -1;
acd = &acc->acd;
_mutex_lock(&acd->mu);
for (;;) {
new_tail = acd->sendq_tail + 1;
if (new_tail >= acd->sendq_size)
new_tail = 0;
if (new_tail != acd->sendq_free)
break;
/* put list is full */
if (acd->flags & _NTO_COF_NONBLOCK) {
_mutex_unlock(&acd->mu);
errno = EAGAIN;
return -1;
}
pthread_cond_wait(&acd->block_con, &acd->mu);
}
aph = &acd->sendq[acd->sendq_tail];
acd->sendq_tail = new_tail;
aph->err = 0;
aph->iov = (iov_t *)iov;
aph->parts = parts;
aph->handle = handle;
aph->cb = call_back;
err = _asyncmsg_put_trigger(coid, acc);
_mutex_unlock(&acd->mu);
return err;
}
int asyncmsg_put(int coid, const void *buff, size_t size, unsigned handle, int (*call_back)(int err, void* buf, unsigned handle))
{
return asyncmsg_putv(coid, (iov_t *)buff, (int)-size, handle, call_back);
}
__SRCVERSION("asyncmsg_put.c $Rev: 153052 $");

23
lib/asyncmsg/common.mk Normal file
View File

@@ -0,0 +1,23 @@
#
# Copyright 2004, QNX Software Systems Ltd. All Rights Reserved.
#
# This source code may contain confidential information of QNX Software
# Systems Ltd. (QSSL) and its licensors. Any use, reproduction,
# modification, disclosure, distribution or transfer of this software,
# or any software which includes or is based upon any of this code, is
# prohibited unless expressly authorized by QSSL by written agreement. For
# more information (including whether this source code file has been
# published) please email licensing@qnx.com.
#
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
define PINFO
PINFO DESCRIPTION = Asynchronous Message Passing Library
endef
INSTALLDIR=usr/lib
NAME=asyncmsg
USEFILE=
include $(MKFILES_ROOT)/qtargets.mk

View File

@@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

45
lib/asyncmsg/module.tmpl Normal file
View File

@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<module name="asyncmsg">
<type>Element</type>
<classification>SDK</classification>
<supports>
<availability ref="ostargets"/>
</supports>
<source available="false">
<location type="">.</location>
</source>
<GroupOwner>os</GroupOwner>
<contents>
<component id="SharedObj" generated="true">
<kind type="library"/>
<location basedir="{cpu}/so{.:endian}" runtime="true">
libasyncmsg.so
</location>
</component>
<component id="SharedArchive" generated="true">
<kind type="library"/>
<location runtime="false" basedir="{cpu}/so{.:endian}">
libasyncmsgS.a
</location>
</component>
<component id="Archive" generated="true">
<kind type="library"/>
<location basedir="{cpu}/a{.:endian}" runtime="false">
libasyncmsg.a
</location>
</component>
</contents>
<!-- Dependencies -->
<requires>
<part build="false" location="services/system"/>
</requires>
</module>

View File

@@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

8
lib/asyncmsg/sh/Makefile Normal file
View File

@@ -0,0 +1,8 @@
LIST=VARIANTS
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1,8 @@
LIST=CPU
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1,127 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <errno.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
char *msg = "AsyncMsg Passing";
int chid = -1, coid;
int getisready = 0;
void *get_thread(void *arg)
{
struct _asyncmsg_get_header *agh, *agh1;
/* async channel */
if ((chid = asyncmsg_channel_create(_NTO_CHF_SENDER_LEN, 0666, 2048, 5, NULL, NULL)) == -1) {
perror("channel_create");
return -1;
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return NULL;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d (%d)\n", agh1->info.msglen, strlen(msg) + 1);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return NULL;
}
return NULL;
}
/* The asyncmsg_get() will be blocked, and let's see if a put
* could wake it up
*/
int main(int argc, char **argv)
{
struct _asyncmsg_connection_attr aca;
int pid = 0;
if (argc > 1) {
if ((pid = fork()) == -1) {
perror("fork");
return -1;
}
if (!pid) {
get_thread(0);
return 0;
} else {
/* we lied, the parent don't know the chid in client,
* we assume it's 1 :)
*/
chid = 1;
}
} else {
if ((errno = pthread_create(0, 0, get_thread, NULL)) != EOK) {
perror("pthread_create");
return -1;
}
}
/* Let the get thread block */
sleep(1);
if (chid == -1) {
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 1;
if ((coid = asyncmsg_connect_attach(0, pid, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
if ((asyncmsg_put(coid, msg, strlen(msg) + 1, 0, 0)) == -1) {
perror("put");
return -1;
}
sleep(1);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return NULL;
}
return 0;
}
__SRCVERSION("block_get.c $Rev: 153052 $");

View File

@@ -0,0 +1,98 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
int callback(int err, void *cmsg, unsigned handle)
{
printf("Callback: err = %d, msg = %p, handle = %d\n",
err, cmsg, handle);
return 0;
}
/*
* Multiple put, then see if get could got all of them.
*/
int main()
{
int chid, coid, i;
struct _asyncmsg_connection_attr aca;
struct _asyncmsg_get_header *agh, *agh1;
char msg[3][80];
if ((chid = asyncmsg_channel_create(_NTO_CHF_SENDER_LEN, 0666, 2048, 5, NULL, NULL)) == -1) {
perror("channel_create");
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 3;
if ((coid = asyncmsg_connect_attach(0, 0, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
for (i = 0; i < 3; i++) {
sprintf(msg[i], "Async Message Passing (msgid %d)\n", i);
if ((asyncmsg_put(coid, msg[i], strlen(msg[i]) + 1, 1234, callback)) == -1) {
perror("put");
return -1;
}
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return -1;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d (%d)\n", agh1->info.msglen, strlen(msg) + 1);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
sleep(1);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return -1;
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return -1;
}
return 0;
}
__SRCVERSION("bulk_put.c $Rev: 153052 $");

View File

@@ -0,0 +1,20 @@
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
USEFILE=
TESTS = $(basename $(notdir $(SRCS)))
INSTALLDIR=/dev/null
ICLEAN=$(TESTS)
ALL_DEPENDENCIES=$(TESTS)
LIBS += asyncmsg
EXTRA_LIBVPATH=$(PROJECT_ROOT)/../$(CPU)/a.be
include $(MKFILES_ROOT)/qtargets.mk
$(TESTS): %: %.o
$(TARGET_BUILD)

View File

@@ -0,0 +1,146 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <errno.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
int num_callback_run = 0;
int chid;
int callback(int err, void *cmsg, unsigned handle)
{
num_callback_run++;
printf("Callback: err = %d, msg = %p, handle = %d\n",
err, cmsg, handle);
return 0;
}
void * thread_for_get(void *arg)
{
int pchid = (int)arg;
struct _pulse pulse;
struct _asyncmsg_get_header *agh, *agh1;
/* waiting for the event */
if (MsgReceivePulse(pchid, &pulse, sizeof(pulse), NULL) == -1) {
perror("MsgReceivePulse");
return NULL;
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return NULL;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d\n", agh1->info.msglen);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
return 0;
}
/*
* No trigger for put, but we force an flush(), see if all
* messages could be pushed out.
*/
int main()
{
int coid, pchid, i;
struct sigevent gev;
struct _asyncmsg_connection_attr aca;
char msg[4][80];
/* prepare the event */
if ((pchid = ChannelCreate(0)) == -1) {
perror("ChannelCreate");
return -1;
}
if ((errno = pthread_create(0, 0, thread_for_get, (void *)pchid)) != EOK)
{
perror("pthread_create");
return -1;
}
if ((gev.sigev_coid = ConnectAttach(0, 0, pchid, _NTO_SIDE_CHANNEL, 0)) == -1)
{
perror("ConnectAttach");
return -1;
}
gev.sigev_notify = SIGEV_PULSE;
gev.sigev_priority = SIGEV_PULSE_PRIO_INHERIT;
/* async channel */
if ((chid = asyncmsg_channel_create(_NTO_CHF_SENDER_LEN, 0666, 2048, 5, &gev, NULL)) == -1) {
perror("channel_create");
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 0;
aca.call_back = callback;
if ((coid = asyncmsg_connect_attach(0, 0, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
/* put up 4 messages */
for (i = 0; i < 2; i++) {
sprintf(msg[i], "Async Message Passing (msgid %d)\n", i);
if ((asyncmsg_put(coid, msg[i], strlen(msg[i]) + 1, 1234, callback)) == -1) {
perror("put");
return -1;
}
}
asyncmsg_flush(coid, 0);
/* give the put callback a chance to run */
while (num_callback_run < 2)
delay(500);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return -1;
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return -1;
}
return 0;
}
__SRCVERSION("flush_put.c $Rev: 153052 $");

View File

@@ -0,0 +1,123 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
char *msg = "AsyncMsg Passing";
int callback(int err, void *cmsg, unsigned handle)
{
printf("Callback: err = %d, msg = %p (%p), handle = %d\n",
err, cmsg, msg, handle);
return 0;
}
/*
* Simple test. Create a channel, connect to it, put a message,
* get them, done
*/
int main()
{
int chid, coid, pchid;
struct sigevent gev;
struct _pulse pulse;
struct _asyncmsg_connection_attr aca;
struct _asyncmsg_get_header *agh, *agh1;
/* prepare the event */
if ((pchid = ChannelCreate(0)) == -1) {
perror("ChannelCreate");
return -1;
}
if ((gev.sigev_coid = ConnectAttach(0, 0, pchid, _NTO_SIDE_CHANNEL, 0)) == -1)
{
perror("ConnectAttach");
return -1;
}
gev.sigev_notify = SIGEV_PULSE;
gev.sigev_priority = SIGEV_PULSE_PRIO_INHERIT;
/* async channel */
if ((chid = asyncmsg_channel_create(0, 0666, 2048, 5, &gev, NULL)) == -1) {
perror("channel_create");
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 1;
aca.call_back = callback;
if ((coid = asyncmsg_connect_attach(0, 0, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
if ((asyncmsg_put(coid, msg, strlen(msg) + 1, 0, 0)) == -1) {
perror("put");
return -1;
}
/* waiting for the event */
if (MsgReceivePulse(pchid, &pulse, sizeof(pulse), NULL) == -1) {
perror("MsgReceivePulse");
return -1;
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return -1;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d (%d)\n", agh1->info.msglen, strlen(msg) + 1);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
/* give the callback a chance to run */
sleep(1);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return -1;
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return -1;
}
return 0;
}
__SRCVERSION("pulse_get.c $Rev: 153052 $");

View File

@@ -0,0 +1,98 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
char *msg = "AsyncMsg Passing";
int callback(int err, void *cmsg, unsigned handle)
{
printf("Callback: err = %d, msg = %p (%p), handle = %d\n",
err, cmsg, msg, handle);
return 0;
}
/*
* Simple test. Create a channel, connect to it, put a message,
* get them, done
*/
int main()
{
int chid, coid;
struct _asyncmsg_connection_attr aca;
struct _asyncmsg_get_header *agh, *agh1;
if ((chid = asyncmsg_channel_create(0, 0666, 2048, 5, NULL, NULL)) == -1) {
perror("channel_create");
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 1;
if ((coid = asyncmsg_connect_attach(0, 0, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
if ((asyncmsg_put(coid, msg, strlen(msg) + 1, 1234, callback)) == -1) {
perror("put");
return -1;
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return -1;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d (%d)\n", agh1->info.msglen, strlen(msg) + 1);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
sleep(1);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return -1;
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return -1;
}
return 0;
}
__SRCVERSION("put_and_get.c $Rev: 153052 $");

View File

@@ -0,0 +1,127 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/asyncmsg.h>
int callback(int err, void *cmsg, unsigned handle)
{
printf("Callback: err = %d, msg = %p, handle = %d\n",
err, cmsg, handle);
return 0;
}
/*
* Set the get trigger to 2 seconds, put up 4 messages, see we could get a
* notification for get after 2 seconds.
*/
int main()
{
int chid, coid, pchid, i;
struct sigevent gev;
struct _pulse pulse;
struct _asyncmsg_connection_attr aca;
struct _asyncmsg_get_header *agh, *agh1;
char msg[4][80];
/* prepare the event */
if ((pchid = ChannelCreate(0)) == -1) {
perror("ChannelCreate");
return -1;
}
if ((gev.sigev_coid = ConnectAttach(0, 0, pchid, _NTO_SIDE_CHANNEL, 0)) == -1)
{
perror("ConnectAttach");
return -1;
}
gev.sigev_notify = SIGEV_PULSE;
gev.sigev_priority = SIGEV_PULSE_PRIO_INHERIT;
/* async channel */
if ((chid = asyncmsg_channel_create(_NTO_CHF_SENDER_LEN, 0666, 2048, 5, &gev, NULL)) == -1) {
perror("channel_create");
return -1;
}
memset(&aca, 0, sizeof(aca));
aca.buffer_size = 2048;
aca.max_num_buffer = 5;
aca.trigger_num_msg = 0;
aca.trigger_time.nsec = 2000000000L;
aca.trigger_time.interval_nsec = 0;
aca.call_back = callback;
if ((coid = asyncmsg_connect_attach(0, 0, chid, 0, 0, &aca)) == -1) {
perror("connect_attach");
return -1;
}
/* put up 4 messages */
for (i = 0; i < 4; i++) {
sprintf(msg[i], "Async Message Passing (msgid %d)\n", i);
if ((asyncmsg_put(coid, msg[i], strlen(msg[i]) + 1, 1234, callback)) == -1) {
perror("put");
return -1;
}
}
/* waiting for the event */
if (MsgReceivePulse(pchid, &pulse, sizeof(pulse), NULL) == -1) {
perror("MsgReceivePulse");
return -1;
}
if ((agh = asyncmsg_get(chid)) == NULL) {
perror("get");
return -1;
}
printf("Got message(s): \n\n");
while (agh1 = agh) {
agh = agh1->next;
printf("from process: %d (%d)\n", agh1->info.pid, getpid());
printf("msglen: %d (%d)\n", agh1->info.msglen, strlen(msg) + 1);
printf("srclen: %d\n", agh1->info.srcmsglen);
printf("err: %d\n", agh1->err);
printf("parts: %d\n", agh1->parts);
printf("msg: %s\n\n", (char *)agh1->iov->iov_base);
asyncmsg_free(agh1);
}
/* give the callback a chance to run */
sleep(1);
if (asyncmsg_connect_detach(coid) == -1) {
perror("connect_detach");
return -1;
}
if (asyncmsg_channel_destroy(chid) == -1) {
perror("channel_detach");
return -1;
}
return 0;
}
__SRCVERSION("timer_put.c $Rev: 153052 $");

View File

@@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

2
lib/bessel/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=CPU
include recurse.mk

2
lib/bessel/arm/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

25
lib/bessel/common.mk Normal file
View File

@@ -0,0 +1,25 @@
#
# Copyright 2004, QNX Software Systems Ltd. All Rights Reserved.
#
# This source code may contain confidential information of QNX Software
# Systems Ltd. (QSSL) and its licensors. Any use, reproduction,
# modification, disclosure, distribution or transfer of this software,
# or any software which includes or is based upon any of this code, is
# prohibited unless expressly authorized by QSSL by written agreement. For
# more information (including whether this source code file has been
# published) please email licensing@qnx.com.
#
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
define PINFO
PINFO DESCRIPTION=Bessel math functions library
endef
include $(MKFILES_ROOT)/qtargets.mk
ifeq ($(filter g, $(VARIANTS)),)
CCFLAGS += -O2
endif

509
lib/bessel/e_j0.c Normal file
View File

@@ -0,0 +1,509 @@
/* @(#)e_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_j0.c,v 1.8 1995/05/10 20:45:23 jtc Exp $";
#endif
/* __ieee754_j0(x), __ieee754_y0(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j0(x):
* 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
* 2. Reduce x to |x| since j0(x)=j0(-x), and
* for x in (0,2)
* j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x;
* (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
* for x in (2,inf)
* j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* as follow:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (cos(x) + sin(x))
* sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j0(nan)= nan
* j0(0) = 1
* j0(inf) = 0
*
* Method -- y0(x):
* 1. For x<2.
* Since
* y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
* therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
* We use the following function to approximate y0,
* y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
* where
* U(z) = u00 + u01*z + ... + u06*z^6
* V(z) = 1 + v01*z + ... + v04*z^4
* with absolute approximation error bounded by 2**-72.
* Note: For tiny x, U/V = u0 and j0(x)~1, hence
* y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
* 2. For x>=2.
* y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* by the method mentioned above.
* 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static double pzero(double), qzero(double);
#else
static double pzero(), qzero();
#endif
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0, 2.00] */
R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */
S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */
S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */
S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */
S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
#ifdef __STDC__
double __ieee754_j0(double x)
#else
double __ieee754_j0(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v;
int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/(x*x);
x = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*cc-v*ss)/sqrt(x);
}
return z;
}
if(ix<0x3f200000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x3e400000) return one; /* |x|<2**-27 */
else return one - 0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3FF00000) { /* |x| < 1.00 */
return one + z*(-0.25+(r/s));
} else {
u = 0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
#ifdef __STDC__
static const double
#else
static double
#endif
u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
#ifdef __STDC__
double __ieee754_y0(double x)
#else
double __ieee754_y0(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
int32_t hx,ix,lx;
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
}
return z;
}
if(ix<=0x3e400000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_log(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));
}
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */
-8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */
-2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */
-2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */
-5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */
};
#ifdef __STDC__
static const double pS8[5] = {
#else
static double pS8[5] = {
#endif
1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */
3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */
4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */
1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */
4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */
};
#ifdef __STDC__
static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */
-7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */
-4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */
-6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */
-3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */
-3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */
};
#ifdef __STDC__
static const double pS5[5] = {
#else
static double pS5[5] = {
#endif
6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */
1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */
5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */
9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */
2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */
};
#ifdef __STDC__
static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */
-7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */
-2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */
-2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */
-5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */
-3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */
};
#ifdef __STDC__
static const double pS3[5] = {
#else
static double pS3[5] = {
#endif
3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */
3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */
1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */
1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */
1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */
};
#ifdef __STDC__
static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */
-7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */
-1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */
-7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */
-1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */
-3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */
};
#ifdef __STDC__
static const double pS2[5] = {
#else
static double pS2[5] = {
#endif
2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */
1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */
2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */
1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */
1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
};
#ifdef __STDC__
static double pzero(double x)
#else
static double pzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pR8; q= pS8;}
else if(ix>=0x40122E8B){p = pR5; q= pS5;}
else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
else if(ix>=0x40000000){p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate pzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */
1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */
5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */
8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */
3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */
};
#ifdef __STDC__
static const double qS8[6] = {
#else
static double qS8[6] = {
#endif
1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */
8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */
1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */
8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */
8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */
-3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */
};
#ifdef __STDC__
static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */
7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */
5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */
1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */
1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */
1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */
};
#ifdef __STDC__
static const double qS5[6] = {
#else
static double qS5[6] = {
#endif
8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */
2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */
1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */
5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */
3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */
-5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */
};
#ifdef __STDC__
static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */
7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */
3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */
4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */
1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */
1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */
};
#ifdef __STDC__
static const double qS3[6] = {
#else
static double qS3[6] = {
#endif
4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */
7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */
3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */
6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */
2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */
-1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */
};
#ifdef __STDC__
static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */
7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */
1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */
1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */
3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */
1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */
};
#ifdef __STDC__
static const double qS2[6] = {
#else
static double qS2[6] = {
#endif
3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */
2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */
8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */
8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */
2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */
-5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
};
#ifdef __STDC__
static double qzero(double x)
#else
static double qzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qR8; q= qS8;}
else if(ix>=0x40122E8B){p = qR5; q= qS5;}
else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
else if(ix>=0x40000000){p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-.125 + r/s)/x;
}

465
lib/bessel/e_j0f.c Normal file
View File

@@ -0,0 +1,465 @@
/* e_j0f.c -- float version of e_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_j0f.c,v 1.4 1995/05/10 20:45:25 jtc Exp $";
#endif
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static float pzerof(float), qzerof(float);
#else
static float pzerof(), qzerof();
#endif
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0, 2.00] */
R02 = 1.5625000000e-02, /* 0x3c800000 */
R03 = -1.8997929874e-04, /* 0xb947352e */
R04 = 1.8295404516e-06, /* 0x35f58e88 */
R05 = -4.6183270541e-09, /* 0xb19eaf3c */
S01 = 1.5619102865e-02, /* 0x3c7fe744 */
S02 = 1.1692678527e-04, /* 0x38f53697 */
S03 = 5.1354652442e-07, /* 0x3509daa6 */
S04 = 1.1661400734e-09; /* 0x30a045e8 */
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
#ifdef __STDC__
float __ieee754_j0f(float x)
#else
float __ieee754_j0f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return one/(x*x);
x = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(x);
}
return z;
}
if(ix<0x39000000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x32000000) return one; /* |x|<2**-27 */
else return one - (float)0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3F800000) { /* |x| < 1.00 */
return one + z*((float)-0.25+(r/s));
} else {
u = (float)0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
#ifdef __STDC__
static const float
#else
static float
#endif
u00 = -7.3804296553e-02, /* 0xbd9726b5 */
u01 = 1.7666645348e-01, /* 0x3e34e80d */
u02 = -1.3818567619e-02, /* 0xbc626746 */
u03 = 3.4745343146e-04, /* 0x39b62a69 */
u04 = -3.8140706238e-06, /* 0xb67ff53c */
u05 = 1.9559013964e-08, /* 0x32a802ba */
u06 = -3.9820518410e-11, /* 0xae2f21eb */
v01 = 1.2730483897e-02, /* 0x3c509385 */
v02 = 7.6006865129e-05, /* 0x389f65e0 */
v03 = 2.5915085189e-07, /* 0x348b216c */
v04 = 4.4111031494e-10; /* 0x2ff280c2 */
#ifdef __STDC__
float __ieee754_y0f(float x)
#else
float __ieee754_y0f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(ix>=0x7f800000) return one/(x+x*x);
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x80000000) z = (invsqrtpi*ss)/sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
if(ix<=0x32000000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_logf(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0f(x)*__ieee754_logf(x)));
}
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-7.0312500000e-02, /* 0xbd900000 */
-8.0816707611e+00, /* 0xc1014e86 */
-2.5706311035e+02, /* 0xc3808814 */
-2.4852163086e+03, /* 0xc51b5376 */
-5.2530439453e+03, /* 0xc5a4285a */
};
#ifdef __STDC__
static const float pS8[5] = {
#else
static float pS8[5] = {
#endif
1.1653436279e+02, /* 0x42e91198 */
3.8337448730e+03, /* 0x456f9beb */
4.0597855469e+04, /* 0x471e95db */
1.1675296875e+05, /* 0x47e4087c */
4.7627726562e+04, /* 0x473a0bba */
};
#ifdef __STDC__
static const float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.1412546255e-11, /* 0xad48c58a */
-7.0312492549e-02, /* 0xbd8fffff */
-4.1596107483e+00, /* 0xc0851b88 */
-6.7674766541e+01, /* 0xc287597b */
-3.3123129272e+02, /* 0xc3a59d9b */
-3.4643338013e+02, /* 0xc3ad3779 */
};
#ifdef __STDC__
static const float pS5[5] = {
#else
static float pS5[5] = {
#endif
6.0753936768e+01, /* 0x42730408 */
1.0512523193e+03, /* 0x44836813 */
5.9789707031e+03, /* 0x45bad7c4 */
9.6254453125e+03, /* 0x461665c8 */
2.4060581055e+03, /* 0x451660ee */
};
#ifdef __STDC__
static const float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.5470459075e-09, /* 0xb12f081b */
-7.0311963558e-02, /* 0xbd8fffb8 */
-2.4090321064e+00, /* 0xc01a2d95 */
-2.1965976715e+01, /* 0xc1afba52 */
-5.8079170227e+01, /* 0xc2685112 */
-3.1447946548e+01, /* 0xc1fb9565 */
};
#ifdef __STDC__
static const float pS3[5] = {
#else
static float pS3[5] = {
#endif
3.5856033325e+01, /* 0x420f6c94 */
3.6151397705e+02, /* 0x43b4c1ca */
1.1936077881e+03, /* 0x44953373 */
1.1279968262e+03, /* 0x448cffe6 */
1.7358093262e+02, /* 0x432d94b8 */
};
#ifdef __STDC__
static const float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.8753431271e-08, /* 0xb3be98b7 */
-7.0303097367e-02, /* 0xbd8ffb12 */
-1.4507384300e+00, /* 0xbfb9b1cc */
-7.6356959343e+00, /* 0xc0f4579f */
-1.1193166733e+01, /* 0xc1331736 */
-3.2336456776e+00, /* 0xc04ef40d */
};
#ifdef __STDC__
static const float pS2[5] = {
#else
static float pS2[5] = {
#endif
2.2220300674e+01, /* 0x41b1c32d */
1.3620678711e+02, /* 0x430834f0 */
2.7047027588e+02, /* 0x43873c32 */
1.5387539673e+02, /* 0x4319e01a */
1.4657617569e+01, /* 0x416a859a */
};
#ifdef __STDC__
static float pzerof(float x)
#else
static float pzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pR8; q= pS8;}
else if(ix>=0x40f71c58){p = pR5; q= pS5;}
else if(ix>=0x4036db68){p = pR3; q= pS3;}
else if(ix>=0x40000000){p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate pzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
7.3242187500e-02, /* 0x3d960000 */
1.1768206596e+01, /* 0x413c4a93 */
5.5767340088e+02, /* 0x440b6b19 */
8.8591972656e+03, /* 0x460a6cca */
3.7014625000e+04, /* 0x471096a0 */
};
#ifdef __STDC__
static const float qS8[6] = {
#else
static float qS8[6] = {
#endif
1.6377603149e+02, /* 0x4323c6aa */
8.0983447266e+03, /* 0x45fd12c2 */
1.4253829688e+05, /* 0x480b3293 */
8.0330925000e+05, /* 0x49441ed4 */
8.4050156250e+05, /* 0x494d3359 */
-3.4389928125e+05, /* 0xc8a7eb69 */
};
#ifdef __STDC__
static const float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.8408595828e-11, /* 0x2da1ec79 */
7.3242180049e-02, /* 0x3d95ffff */
5.8356351852e+00, /* 0x40babd86 */
1.3511157227e+02, /* 0x43071c90 */
1.0272437744e+03, /* 0x448067cd */
1.9899779053e+03, /* 0x44f8bf4b */
};
#ifdef __STDC__
static const float qS5[6] = {
#else
static float qS5[6] = {
#endif
8.2776611328e+01, /* 0x42a58da0 */
2.0778142090e+03, /* 0x4501dd07 */
1.8847289062e+04, /* 0x46933e94 */
5.6751113281e+04, /* 0x475daf1d */
3.5976753906e+04, /* 0x470c88c1 */
-5.3543427734e+03, /* 0xc5a752be */
};
#ifdef __STDC__
static const float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.3774099900e-09, /* 0x3196681b */
7.3241114616e-02, /* 0x3d95ff70 */
3.3442313671e+00, /* 0x405607e3 */
4.2621845245e+01, /* 0x422a7cc5 */
1.7080809021e+02, /* 0x432acedf */
1.6673394775e+02, /* 0x4326bbe4 */
};
#ifdef __STDC__
static const float qS3[6] = {
#else
static float qS3[6] = {
#endif
4.8758872986e+01, /* 0x42430916 */
7.0968920898e+02, /* 0x44316c1c */
3.7041481934e+03, /* 0x4567825f */
6.4604252930e+03, /* 0x45c9e367 */
2.5163337402e+03, /* 0x451d4557 */
-1.4924745178e+02, /* 0xc3153f59 */
};
#ifdef __STDC__
static const float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.5044444979e-07, /* 0x342189db */
7.3223426938e-02, /* 0x3d95f62a */
1.9981917143e+00, /* 0x3fffc4bf */
1.4495602608e+01, /* 0x4167edfd */
3.1666231155e+01, /* 0x41fd5471 */
1.6252708435e+01, /* 0x4182058c */
};
#ifdef __STDC__
static const float qS2[6] = {
#else
static float qS2[6] = {
#endif
3.0365585327e+01, /* 0x41f2ecb8 */
2.6934811401e+02, /* 0x4386ac8f */
8.4478375244e+02, /* 0x44533229 */
8.8293585205e+02, /* 0x445cbbe5 */
2.1266638184e+02, /* 0x4354aa98 */
-5.3109550476e+00, /* 0xc0a9f358 */
};
#ifdef __STDC__
static float qzerof(float x)
#else
static float qzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = qR8; q= qS8;}
else if(ix>=0x40f71c58){p = qR5; q= qS5;}
else if(ix>=0x4036db68){p = qR3; q= qS3;}
else if(ix>=0x40000000){p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-(float).125 + r/s)/x;
}

507
lib/bessel/e_j1.c Normal file
View File

@@ -0,0 +1,507 @@
/* @(#)e_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_j1.c,v 1.8 1995/05/10 20:45:27 jtc Exp $";
#endif
/* __ieee754_j1(x), __ieee754_y1(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j1(x):
* 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
* 2. Reduce x to |x| since j1(x)=-j1(-x), and
* for x in (0,2)
* j1(x) = x/2 + x*z*R0/S0, where z = x*x;
* (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 )
* for x in (2,inf)
* j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* as follow:
* cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (sin(x) + cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j1(nan)= nan
* j1(0) = 0
* j1(inf) = 0
*
* Method -- y1(x):
* 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
* 2. For x<2.
* Since
* y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
* therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
* We use the following function to approximate y1,
* y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
* where for x in [0,2] (abs err less than 2**-65.89)
* U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
* V(z) = 1 + v0[0]*z + ... + v0[4]*z^5
* Note: For tiny x, 1/x dominate y1 and hence
* y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
* 3. For x>=2.
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* by method mentioned above.
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static double pone(double), qone(double);
#else
static double pone(), qone();
#endif
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0,2] */
r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */
r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */
r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */
r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */
s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */
s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */
s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */
s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */
s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
#ifdef __STDC__
double __ieee754_j1(double x)
#else
double __ieee754_j1(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v,y;
int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/x;
y = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(y);
c = cos(y);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure y+y not overflow */
z = cos(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(y);
else {
u = pone(y); v = qone(y);
z = invsqrtpi*(u*cc-v*ss)/sqrt(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x3e400000) { /* |x|<2**-27 */
if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*0.5+r/s);
}
#ifdef __STDC__
static const double U0[5] = {
#else
static double U0[5] = {
#endif
-1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */
5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */
-1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */
2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */
-9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */
};
#ifdef __STDC__
static const double V0[5] = {
#else
static double V0[5] = {
#endif
1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */
2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */
1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */
6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */
1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
};
#ifdef __STDC__
double __ieee754_y1(double x)
#else
double __ieee754_y1(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
int32_t hx,ix,lx;
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = cos(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
else {
u = pone(x); v = qone(x);
z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
}
return z;
}
if(ix<=0x3c900000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));
}
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
#ifdef __STDC__
static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */
1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */
4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */
3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */
7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */
};
#ifdef __STDC__
static const double ps8[5] = {
#else
static double ps8[5] = {
#endif
1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */
3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */
3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */
9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */
3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */
};
#ifdef __STDC__
static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */
1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */
6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */
1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */
5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */
5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */
};
#ifdef __STDC__
static const double ps5[5] = {
#else
static double ps5[5] = {
#endif
5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */
9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */
5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */
7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */
1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */
};
#ifdef __STDC__
static const double pr3[6] = {
#else
static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */
1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */
3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */
3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */
9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */
4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */
};
#ifdef __STDC__
static const double ps3[5] = {
#else
static double ps3[5] = {
#endif
3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */
3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */
1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */
8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */
1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */
};
#ifdef __STDC__
static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */
1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */
2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */
1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */
1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */
5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */
};
#ifdef __STDC__
static const double ps2[5] = {
#else
static double ps2[5] = {
#endif
2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */
1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */
2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */
1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */
8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
};
#ifdef __STDC__
static double pone(double x)
#else
static double pone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pr8; q= ps8;}
else if(ix>=0x40122E8B){p = pr5; q= ps5;}
else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
else if(ix>=0x40000000){p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate pone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
#ifdef __STDC__
static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */
-1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */
-7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */
-1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */
-4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */
};
#ifdef __STDC__
static const double qs8[6] = {
#else
static double qs8[6] = {
#endif
1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */
7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */
1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */
7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */
6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */
-2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */
};
#ifdef __STDC__
static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */
-1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */
-8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */
-1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */
-1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */
-2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */
};
#ifdef __STDC__
static const double qs5[6] = {
#else
static double qs5[6] = {
#endif
8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */
1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */
1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */
4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */
2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */
-4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */
};
#ifdef __STDC__
static const double qr3[6] = {
#else
static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */
-1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */
-4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */
-5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */
-2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */
-2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */
};
#ifdef __STDC__
static const double qs3[6] = {
#else
static double qs3[6] = {
#endif
4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */
6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */
3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */
5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */
1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */
-1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */
};
#ifdef __STDC__
static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */
-1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */
-2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */
-1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */
-4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */
-2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */
};
#ifdef __STDC__
static const double qs2[6] = {
#else
static double qs2[6] = {
#endif
2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */
2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */
7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */
7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */
1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */
-4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
};
#ifdef __STDC__
static double qone(double x)
#else
static double qone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40122E8B){p = qr5; q= qs5;}
else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
else if(ix>=0x40000000){p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (.375 + r/s)/x;
}

465
lib/bessel/e_j1f.c Normal file
View File

@@ -0,0 +1,465 @@
/* e_j1f.c -- float version of e_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_j1f.c,v 1.4 1995/05/10 20:45:31 jtc Exp $";
#endif
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static float ponef(float), qonef(float);
#else
static float ponef(), qonef();
#endif
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0,2] */
r00 = -6.2500000000e-02, /* 0xbd800000 */
r01 = 1.4070566976e-03, /* 0x3ab86cfd */
r02 = -1.5995563444e-05, /* 0xb7862e36 */
r03 = 4.9672799207e-08, /* 0x335557d2 */
s01 = 1.9153760746e-02, /* 0x3c9ce859 */
s02 = 1.8594678841e-04, /* 0x3942fab6 */
s03 = 1.1771846857e-06, /* 0x359dffc2 */
s04 = 5.0463624390e-09, /* 0x31ad6446 */
s05 = 1.2354227016e-11; /* 0x2d59567e */
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
#ifdef __STDC__
float __ieee754_j1f(float x)
#else
float __ieee754_j1f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v,y;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return one/x;
y = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(y);
c = cosf(y);
ss = -s-c;
cc = s-c;
if(ix<0x7f000000) { /* make sure y+y not overflow */
z = cosf(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
else {
u = ponef(y); v = qonef(y);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x32000000) { /* |x|<2**-27 */
if(huge+x>one) return (float)0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*(float)0.5+r/s);
}
#ifdef __STDC__
static const float U0[5] = {
#else
static float U0[5] = {
#endif
-1.9605709612e-01, /* 0xbe48c331 */
5.0443872809e-02, /* 0x3d4e9e3c */
-1.9125689287e-03, /* 0xbafaaf2a */
2.3525259166e-05, /* 0x37c5581c */
-9.1909917899e-08, /* 0xb3c56003 */
};
#ifdef __STDC__
static const float V0[5] = {
#else
static float V0[5] = {
#endif
1.9916731864e-02, /* 0x3ca3286a */
2.0255257550e-04, /* 0x3954644b */
1.3560879779e-06, /* 0x35b602d4 */
6.2274145840e-09, /* 0x31d5f8eb */
1.6655924903e-11, /* 0x2d9281cf */
};
#ifdef __STDC__
float __ieee754_y1f(float x)
#else
float __ieee754_y1f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(ix>=0x7f800000) return one/(x+x*x);
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = -s-c;
cc = s-c;
if(ix<0x7f000000) { /* make sure x+x not overflow */
z = cosf(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/sqrtf(x);
else {
u = ponef(x); v = qonef(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
if(ix<=0x24800000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1f(x)*__ieee754_logf(x)-one/x));
}
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
#ifdef __STDC__
static const float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
1.1718750000e-01, /* 0x3df00000 */
1.3239480972e+01, /* 0x4153d4ea */
4.1205184937e+02, /* 0x43ce06a3 */
3.8747453613e+03, /* 0x45722bed */
7.9144794922e+03, /* 0x45f753d6 */
};
#ifdef __STDC__
static const float ps8[5] = {
#else
static float ps8[5] = {
#endif
1.1420736694e+02, /* 0x42e46a2c */
3.6509309082e+03, /* 0x45642ee5 */
3.6956207031e+04, /* 0x47105c35 */
9.7602796875e+04, /* 0x47bea166 */
3.0804271484e+04, /* 0x46f0a88b */
};
#ifdef __STDC__
static const float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.3199052094e-11, /* 0x2d68333f */
1.1718749255e-01, /* 0x3defffff */
6.8027510643e+00, /* 0x40d9b023 */
1.0830818176e+02, /* 0x42d89dca */
5.1763616943e+02, /* 0x440168b7 */
5.2871520996e+02, /* 0x44042dc6 */
};
#ifdef __STDC__
static const float ps5[5] = {
#else
static float ps5[5] = {
#endif
5.9280597687e+01, /* 0x426d1f55 */
9.9140142822e+02, /* 0x4477d9b1 */
5.3532670898e+03, /* 0x45a74a23 */
7.8446904297e+03, /* 0x45f52586 */
1.5040468750e+03, /* 0x44bc0180 */
};
#ifdef __STDC__
static const float pr3[6] = {
#else
static float pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.0250391081e-09, /* 0x314fe10d */
1.1718686670e-01, /* 0x3defffab */
3.9329774380e+00, /* 0x407bb5e7 */
3.5119403839e+01, /* 0x420c7a45 */
9.1055007935e+01, /* 0x42b61c2a */
4.8559066772e+01, /* 0x42423c7c */
};
#ifdef __STDC__
static const float ps3[5] = {
#else
static float ps3[5] = {
#endif
3.4791309357e+01, /* 0x420b2a4d */
3.3676245117e+02, /* 0x43a86198 */
1.0468714600e+03, /* 0x4482dbe3 */
8.9081134033e+02, /* 0x445eb3ed */
1.0378793335e+02, /* 0x42cf936c */
};
#ifdef __STDC__
static const float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.0771083225e-07, /* 0x33e74ea8 */
1.1717621982e-01, /* 0x3deffa16 */
2.3685150146e+00, /* 0x401795c0 */
1.2242610931e+01, /* 0x4143e1bc */
1.7693971634e+01, /* 0x418d8d41 */
5.0735230446e+00, /* 0x40a25a4d */
};
#ifdef __STDC__
static const float ps2[5] = {
#else
static float ps2[5] = {
#endif
2.1436485291e+01, /* 0x41ab7dec */
1.2529022980e+02, /* 0x42fa9499 */
2.3227647400e+02, /* 0x436846c7 */
1.1767937469e+02, /* 0x42eb5bd7 */
8.3646392822e+00, /* 0x4105d590 */
};
#ifdef __STDC__
static float ponef(float x)
#else
static float ponef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pr8; q= ps8;}
else if(ix>=0x40f71c58){p = pr5; q= ps5;}
else if(ix>=0x4036db68){p = pr3; q= ps3;}
else if(ix>=0x40000000){p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate pone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
#ifdef __STDC__
static const float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-1.0253906250e-01, /* 0xbdd20000 */
-1.6271753311e+01, /* 0xc1822c8d */
-7.5960174561e+02, /* 0xc43de683 */
-1.1849806641e+04, /* 0xc639273a */
-4.8438511719e+04, /* 0xc73d3683 */
};
#ifdef __STDC__
static const float qs8[6] = {
#else
static float qs8[6] = {
#endif
1.6139537048e+02, /* 0x43216537 */
7.8253862305e+03, /* 0x45f48b17 */
1.3387534375e+05, /* 0x4802bcd6 */
7.1965775000e+05, /* 0x492fb29c */
6.6660125000e+05, /* 0x4922be94 */
-2.9449025000e+05, /* 0xc88fcb48 */
};
#ifdef __STDC__
static const float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.0897993405e-11, /* 0xadb7d219 */
-1.0253904760e-01, /* 0xbdd1fffe */
-8.0564479828e+00, /* 0xc100e736 */
-1.8366960144e+02, /* 0xc337ab6b */
-1.3731937256e+03, /* 0xc4aba633 */
-2.6124443359e+03, /* 0xc523471c */
};
#ifdef __STDC__
static const float qs5[6] = {
#else
static float qs5[6] = {
#endif
8.1276550293e+01, /* 0x42a28d98 */
1.9917987061e+03, /* 0x44f8f98f */
1.7468484375e+04, /* 0x468878f8 */
4.9851425781e+04, /* 0x4742bb6d */
2.7948074219e+04, /* 0x46da5826 */
-4.7191835938e+03, /* 0xc5937978 */
};
#ifdef __STDC__
static const float qr3[6] = {
#else
static float qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.0783124372e-09, /* 0xb1ae7d4f */
-1.0253783315e-01, /* 0xbdd1ff5b */
-4.6101160049e+00, /* 0xc0938612 */
-5.7847221375e+01, /* 0xc267638e */
-2.2824453735e+02, /* 0xc3643e9a */
-2.1921012878e+02, /* 0xc35b35cb */
};
#ifdef __STDC__
static const float qs3[6] = {
#else
static float qs3[6] = {
#endif
4.7665153503e+01, /* 0x423ea91e */
6.7386511230e+02, /* 0x4428775e */
3.3801528320e+03, /* 0x45534272 */
5.5477290039e+03, /* 0x45ad5dd5 */
1.9031191406e+03, /* 0x44ede3d0 */
-1.3520118713e+02, /* 0xc3073381 */
};
#ifdef __STDC__
static const float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.7838172539e-07, /* 0xb43f8932 */
-1.0251704603e-01, /* 0xbdd1f475 */
-2.7522056103e+00, /* 0xc0302423 */
-1.9663616180e+01, /* 0xc19d4f16 */
-4.2325313568e+01, /* 0xc2294d1f */
-2.1371921539e+01, /* 0xc1aaf9b2 */
};
#ifdef __STDC__
static const float qs2[6] = {
#else
static float qs2[6] = {
#endif
2.9533363342e+01, /* 0x41ec4454 */
2.5298155212e+02, /* 0x437cfb47 */
7.5750280762e+02, /* 0x443d602e */
7.3939318848e+02, /* 0x4438d92a */
1.5594900513e+02, /* 0x431bf2f2 */
-4.9594988823e+00, /* 0xc09eb437 */
};
#ifdef __STDC__
static float qonef(float x)
#else
static float qonef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
int32_t ix;
p = q = 0; /* Quiet warnings */
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40f71c58){p = qr5; q= qs5;}
else if(ix>=0x4036db68){p = qr3; q= qs3;}
else if(ix>=0x40000000){p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return ((float).375 + r/s)/x;
}

303
lib/bessel/e_jn.c Normal file
View File

@@ -0,0 +1,303 @@
/* @(#)e_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_jn.c,v 1.9 1995/05/10 20:45:34 jtc Exp $";
#endif
/*
* __ieee754_jn(n, x), __ieee754_yn(n, x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static const double
#else
static double
#endif
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
one = 1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */
#ifdef __STDC__
static const double zero = 0.00000000000000000000e+00;
#else
static double zero = 0.00000000000000000000e+00;
#endif
#ifdef __STDC__
double __ieee754_jn(int n, double x)
#else
double __ieee754_jn(n,x)
int n; double x;
#endif
{
int32_t i,hx,ix,lx, sgn;
double a, b, temp, di;
double z, w;
temp = 0; /* Quiet warnings */
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0(x));
if(n==1) return(__ieee754_j1(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabs(x);
if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */
b = zero;
else if((double)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = cos(x)+sin(x); break;
case 1: temp = -cos(x)+sin(x); break;
case 2: temp = -cos(x)-sin(x); break;
case 3: temp = cos(x)-sin(x); break;
}
b = invsqrtpi*temp/sqrt(x);
} else {
a = __ieee754_j0(x);
b = __ieee754_j1(x);
for(i=1;i<n;i++){
temp = b;
b = b*((double)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
}
} else {
if(ix<0x3e100000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (double)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
double t,v;
double q0,q1,h,tmp; int32_t k,m;
w = (n+n)/(double)x; h = 2.0/(double)x;
q0 = w; z = w+h; q1 = w*z - 1.0; k=1;
while(q1<1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_log(fabs(v*tmp));
if(tmp<7.09782712893383973096e+02) {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>1e100) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
#ifdef __STDC__
double __ieee754_yn(int n, double x)
#else
double __ieee754_yn(n,x)
int n; double x;
#endif
{
int32_t i,hx,ix,lx;
int32_t sign;
double a, b, temp;
temp = 0; /* Quiet warnings */
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<1);
}
if(n==0) return(__ieee754_y0(x));
if(n==1) return(sign*__ieee754_y1(x));
if(ix==0x7ff00000) return zero;
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = sin(x)-cos(x); break;
case 1: temp = -sin(x)-cos(x); break;
case 2: temp = -sin(x)+cos(x); break;
case 3: temp = sin(x)+cos(x); break;
}
b = invsqrtpi*temp/sqrt(x);
} else {
u_int32_t high;
a = __ieee754_y0(x);
b = __ieee754_y1(x);
/* quit if b is -inf */
GET_HIGH_WORD(high,b);
for(i=1;i<n&&high!=0xfff00000;i++){
temp = b;
b = ((double)(i+i)/x)*b - a;
GET_HIGH_WORD(high,b);
a = temp;
}
}
if(sign>0) return b; else return -b;
}

231
lib/bessel/e_jnf.c Normal file
View File

@@ -0,0 +1,231 @@
/* e_jnf.c -- float version of e_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_jnf.c,v 1.5 1995/05/10 20:45:37 jtc Exp $";
#endif
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
static const float
#else
static float
#endif
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
two = 2.0000000000e+00, /* 0x40000000 */
one = 1.0000000000e+00; /* 0x3F800000 */
#ifdef __STDC__
static const float zero = 0.0000000000e+00;
#else
static float zero = 0.0000000000e+00;
#endif
#ifdef __STDC__
float __ieee754_jnf(int n, float x)
#else
float __ieee754_jnf(n,x)
int n; float x;
#endif
{
int32_t i,hx,ix, sgn;
float a, b, temp, di;
float z, w;
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if(ix>0x7f800000) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0f(x));
if(n==1) return(__ieee754_j1f(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabsf(x);
if(ix==0||ix>=0x7f800000) /* if x is 0 or inf */
b = zero;
else if((float)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
a = __ieee754_j0f(x);
b = __ieee754_j1f(x);
for(i=1;i<n;i++){
temp = b;
b = b*((float)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
} else {
if(ix<0x30800000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*(float)0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (float)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
float t,v;
float q0,q1,h,tmp; int32_t k,m;
w = (n+n)/(float)x; h = (float)2.0/(float)x;
q0 = w; z = w+h; q1 = w*z - (float)1.0; k=1;
while(q1<(float)1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_logf(fabsf(v*tmp));
if(tmp<(float)8.8721679688e+01) {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>(float)1e10) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0f(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
#ifdef __STDC__
float __ieee754_ynf(int n, float x)
#else
float __ieee754_ynf(n,x)
int n; float x;
#endif
{
int32_t i,hx,ix,ib;
int32_t sign;
float a, b, temp;
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if(ix>0x7f800000) return x+x;
if(ix==0) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<1);
}
if(n==0) return(__ieee754_y0f(x));
if(n==1) return(sign*__ieee754_y1f(x));
if(ix==0x7f800000) return zero;
a = __ieee754_y0f(x);
b = __ieee754_y1f(x);
/* quit if b is -inf */
GET_FLOAT_WORD(ib,b);
for(i=1;i<n&&ib!=0xff800000;i++){
temp = b;
b = ((float)(i+i)/x)*b - a;
GET_FLOAT_WORD(ib,b);
a = temp;
}
if(sign>0) return b; else return -b;
}

243
lib/bessel/math_private.h Normal file
View File

@@ -0,0 +1,243 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $Id: math_private.h 153052 2007-11-02 21:10:56Z coreos $
*/
#ifndef _MATH_PRIVATE_H_
#define _MATH_PRIVATE_H_
//#include <machine/endian.h>
#include <sys/types.h>
#include <inttypes.h>
typedef uint32_t u_int32_t;
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
ix1 = *((1-n0)+(int*)&x); * low word of x *
to dig two 32 bit words out of the 64 bit IEEE floating point
value. That is non-ANSI, and, moreover, the gcc instruction
scheduler gets it wrong. We instead use the following macros.
Unlike the original code, we determine the endianness at compile
time, not at run time; I don't see much benefit to selecting
endianness at run time. */
/* A union which permits us to convert between a double and two 32 bit
ints.
TF-QNX NOTE:
It is actually illegal to reference an element of a union as
one type and then use another member of the union ... the
results are undefined and actually do crop up ie SET_LOW_WORD:
fmr f10,f24 ;Move fp to 10
stfd f10,8(r1) ;Store in memory
lwz r9,8(r1) ;Pull out int32 values
lwz r10,12(r1)
li r10,0 ;Access lower int32 member
;and store 0 in it
fmr f30,f10 ;Access the double member
;it won't be the same as int32
This is fixed by adding the volatile keyword to the macros.
*/
#if defined(__BIGENDIAN__)
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
#endif
#if defined(__LITTLEENDIAN__)
#if defined(__ARM__)
/*
* FIXME: with the soft-float, ARM FP is bigendian regardless of the CPU...
*/
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
} ieee_double_shape_type;
#else // !defined(__ARM__)
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
#endif // defined(__ARM__)
#endif
/* Get two 32 bit ints from a double. */
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
volatile ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
/* Get the more significant 32 bit int from a double. */
#define GET_HIGH_WORD(i,d) \
do { \
volatile ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
/* Get the less significant 32 bit int from a double. */
#define GET_LOW_WORD(i,d) \
do { \
volatile ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
/* Set a double from two 32 bit ints. */
#define INSERT_WORDS(d,ix0,ix1) \
do { \
volatile ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
/* Set the more significant 32 bits of a double from an int. */
#define SET_HIGH_WORD(d,v) \
do { \
volatile ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
/* Set the less significant 32 bits of a double from an int. */
#define SET_LOW_WORD(d,v) \
do { \
volatile ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)
/* A union which permits us to convert between a float and a 32 bit
int. */
typedef union
{
float value;
u_int32_t word;
} ieee_float_shape_type;
/* Get a 32 bit int from a float. */
#define GET_FLOAT_WORD(i,d) \
do { \
volatile ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
/* Set a float from a 32 bit int. */
#define SET_FLOAT_WORD(d,i) \
do { \
volatile ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
/* ieee style elementary functions */
#if 0
extern double __ieee754_log __P((double));
#else
#define __ieee754_log log
#endif
extern double __ieee754_j0 __P((double));
extern double __ieee754_j1 __P((double));
extern double __ieee754_y0 __P((double));
extern double __ieee754_y1 __P((double));
extern double __ieee754_jn __P((int,double));
extern double __ieee754_yn __P((int,double));
/* ieee style elementary float functions */
#if 0
extern float __ieee754_logf __P((float));
#else
#define __ieee754_logf logf
#endif
extern float __ieee754_j0f __P((float));
extern float __ieee754_j1f __P((float));
extern float __ieee754_y0f __P((float));
extern float __ieee754_y1f __P((float));
extern float __ieee754_jnf __P((int,float));
extern float __ieee754_ynf __P((int,float));
#if 0
extern float __ieee754_remainderf __P((float,float));
extern int __ieee754_rem_pio2f __P((float,float*));
extern float __ieee754_scalbf __P((float,float));
/* float versions of fdlibm kernel functions */
extern float __kernel_sinf __P((float,float,int));
extern float __kernel_cosf __P((float,float));
extern float __kernel_tanf __P((float,float,int));
extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
#endif
#endif /* _MATH_PRIVATE_H_ */

2
lib/bessel/mips/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

36
lib/bessel/module.tmpl Normal file
View File

@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<module name="bessel">
<type>Element</type>
<classification>SDK</classification>
<supports>
<availability ref="ostargets"/>
</supports>
<source available="false">
<location type="">.</location>
</source>
<GroupOwner>os</GroupOwner>
<contents>
<component id="SharedObj" generated="true">
<kind type="library"/>
<location basedir="{cpu}/so{.:endian}" runtime="true">
libbessel.so
</location>
</component>
<component id="Archive" generated="true">
<kind type="library"/>
<location basedir="{cpu}/a{.:endian}" runtime="false">
libbessel.a
</location>
</component>
</contents>
</module>

80
lib/bessel/old-math.h Normal file
View File

@@ -0,0 +1,80 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#ifndef _OLD_MATH_H_INCLUDED
#define _OLD_MATH_H_INCLUDED
#if defined(__WATCOMC__) && !defined(_ENABLE_AUTODEPEND)
#pragma read_only_file;
#endif
#ifndef __PLATFORM_H_INCLUDED
#include <sys/platform.h>
#endif
#ifndef _MATH_H_INCLUDED
#include <math.h>
#endif
#include <_pack64.h>
/*
We are always going to use the IEEE version of the old
math library in conjunction with the new Dinkum math
library.
*/
#define _IEEE_LIBM 1
__BEGIN_DECLS
#if 0
#if defined(__EXT_MATH_199001)
extern double j0 __P((double)) __attribute__((__const__));
extern double j1 __P((double)) __attribute__((__const__));
extern double jn __P((int, double)) __attribute__((__const__));
extern double y0 __P((double)) __attribute__((__const__));
extern double y1 __P((double)) __attribute__((__const__));
extern double yn __P((int, double)) __attribute__((__const__));
#if !defined(_XOPEN_SOURCE)
extern float j0f __P((float)) __attribute__((__const__));
extern float j1f __P((float)) __attribute__((__const__));
extern float jnf __P((int, float)) __attribute__((__const__));
extern float y0f __P((float)) __attribute__((__const__));
extern float y1f __P((float)) __attribute__((__const__));
extern float ynf __P((int, float)) __attribute__((__const__));
#endif
#endif
#endif
__END_DECLS
#endif /* _MATH_H_ */

10
lib/bessel/package.qpg Normal file
View File

@@ -0,0 +1,10 @@
<QPG:Generation>
<QPG:Owner file="owner.qpg"/>
<QPG:Values>
<QPG:Files>
<QPG:Add file="*/a*/libbessel.a" pinfo="$"/>
<QPG:Add file="*/so*/libbesselS.a" pinfo="$"/>
<QPG:Add file="*/so*/libbessel.so" pinfo="$"/>
</QPG:Files>
</QPG:Values>
</QPG:Generation>

2
lib/bessel/ppc/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

2
lib/bessel/sh/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

88
lib/bessel/w_j0.c Normal file
View File

@@ -0,0 +1,88 @@
/* @(#)w_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_j0.c,v 1.6 1995/05/10 20:49:11 jtc Exp $";
#endif
/*
* wrapper j0(double x), y0(double x)
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
double j0(double x) /* wrapper j0 */
#else
double j0(x) /* wrapper j0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0(x);
#else
double z = __ieee754_j0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard(x,x,34); /* j0(|x|>X_TLOSS) */
} else
return z;
#endif
}
#ifdef __STDC__
double y0(double x) /* wrapper y0 */
#else
double y0(x) /* wrapper y0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0(x);
#else
double z;
z = __ieee754_y0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard(x,x,8);
else
/* d = zero/(x-x); */
return __kernel_standard(x,x,9);
}
if(x>X_TLOSS) {
return __kernel_standard(x,x,35); /* y0(x>X_TLOSS) */
} else
return z;
#endif
}

93
lib/bessel/w_j0f.c Normal file
View File

@@ -0,0 +1,93 @@
/* w_j0f.c -- float version of w_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_j0f.c,v 1.3 1995/05/10 20:49:13 jtc Exp $";
#endif
/*
* wrapper j0f(float x), y0f(float x)
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
float j0f(float x) /* wrapper j0f */
#else
float j0f(x) /* wrapper j0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0f(x);
#else
float z = __ieee754_j0f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j0f(|x|>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,134);
} else
return z;
#endif
}
#ifdef __STDC__
float y0f(float x) /* wrapper y0f */
#else
float y0f(x) /* wrapper y0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0f(x);
#else
float z;
z = __ieee754_y0f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)x,(double)x,108);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)x,(double)x,109);
}
if(x>(float)X_TLOSS) {
/* y0(x>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,135);
} else
return z;
#endif
}

89
lib/bessel/w_j1.c Normal file
View File

@@ -0,0 +1,89 @@
/* @(#)w_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_j1.c,v 1.6 1995/05/10 20:49:15 jtc Exp $";
#endif
/*
* wrapper of j1,y1
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
double j1(double x) /* wrapper j1 */
#else
double j1(x) /* wrapper j1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1(x);
#else
double z;
z = __ieee754_j1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard(x,x,36); /* j1(|x|>X_TLOSS) */
} else
return z;
#endif
}
#ifdef __STDC__
double y1(double x) /* wrapper y1 */
#else
double y1(x) /* wrapper y1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1(x);
#else
double z;
z = __ieee754_y1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard(x,x,10);
else
/* d = zero/(x-x); */
return __kernel_standard(x,x,11);
}
if(x>X_TLOSS) {
return __kernel_standard(x,x,37); /* y1(x>X_TLOSS) */
} else
return z;
#endif
}

94
lib/bessel/w_j1f.c Normal file
View File

@@ -0,0 +1,94 @@
/* w_j1f.c -- float version of w_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_j1f.c,v 1.3 1995/05/10 20:49:17 jtc Exp $";
#endif
/*
* wrapper of j1f,y1f
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
float j1f(float x) /* wrapper j1f */
#else
float j1f(x) /* wrapper j1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1f(x);
#else
float z;
z = __ieee754_j1f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j1(|x|>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,136);
} else
return z;
#endif
}
#ifdef __STDC__
float y1f(float x) /* wrapper y1f */
#else
float y1f(x) /* wrapper y1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1f(x);
#else
float z;
z = __ieee754_y1f(x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)x,(double)x,110);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)x,(double)x,111);
}
if(x>(float)X_TLOSS) {
/* y1(x>X_TLOSS) */
return (float)__kernel_standard((double)x,(double)x,137);
} else
return z;
#endif
}

111
lib/bessel/w_jn.c Normal file
View File

@@ -0,0 +1,111 @@
/* @(#)w_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_jn.c,v 1.6 1995/05/10 20:49:19 jtc Exp $";
#endif
/*
* wrapper jn(int n, double x), yn(int n, double x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
double jn(int n, double x) /* wrapper jn */
#else
double jn(n,x) /* wrapper jn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jn(n,x);
#else
double z;
z = __ieee754_jn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
} else
return z;
#endif
}
#ifdef __STDC__
double yn(int n, double x) /* wrapper yn */
#else
double yn(n,x) /* wrapper yn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_yn(n,x);
#else
double z;
z = __ieee754_yn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
if(x==0.0)
/* d= -one/(x-x); */
return __kernel_standard((double)n,x,12);
else
/* d = zero/(x-x); */
return __kernel_standard((double)n,x,13);
}
if(x>X_TLOSS) {
return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
} else
return z;
#endif
}

90
lib/bessel/w_jnf.c Normal file
View File

@@ -0,0 +1,90 @@
/* w_jnf.c -- float version of w_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable
* license fees to QNX Software Systems before you may reproduce,
* modify or distribute this software, or any work that includes
* all or part of this software. Free development licenses are
* available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email
* licensing@qnx.com.
*
* This file may contain contributions from others. Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/
#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: w_jnf.c,v 1.3 1995/05/10 20:49:21 jtc Exp $";
#endif
#include "old-math.h"
#include "math_private.h"
#ifdef __STDC__
float jnf(int n, float x) /* wrapper jnf */
#else
float jnf(n,x) /* wrapper jnf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jnf(n,x);
#else
float z;
z = __ieee754_jnf(n,x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* jn(|x|>X_TLOSS,n) */
return (float)__kernel_standard((double)n,(double)x,138);
} else
return z;
#endif
}
#ifdef __STDC__
float ynf(int n, float x) /* wrapper ynf */
#else
float ynf(n,x) /* wrapper ynf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_ynf(n,x);
#else
float z;
z = __ieee754_ynf(n,x);
if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
if(x <= (float)0.0){
if(x==(float)0.0)
/* d= -one/(x-x); */
return (float)__kernel_standard((double)n,(double)x,112);
else
/* d = zero/(x-x); */
return (float)__kernel_standard((double)n,(double)x,113);
}
if(x>(float)X_TLOSS) {
/* yn(x>X_TLOSS,n) */
return (float)__kernel_standard((double)n,(double)x,139);
} else
return z;
#endif
}

2
lib/bessel/x86/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

View File

@@ -0,0 +1 @@
include ../../common.mk

2
lib/c/1/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=CPU
include recurse.mk

35
lib/c/1/__stat_check.c Normal file
View File

@@ -0,0 +1,35 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#define _FILE_OFFSET_BITS 32
#include <errno.h>
#include <sys/stat.h>
int __stat_check(const struct stat *st)
{
if (st->st_size < 0 || st->st_size_hi != 0 || st->st_ino_hi != 0 || st->st_blocks_hi != 0) {
errno = EOVERFLOW;
return(-1);
}
return(0);
}
__SRCVERSION("__stat_check.c $Rev: 153052 $");

121
lib/c/1/access.c Normal file
View File

@@ -0,0 +1,121 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <share.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/iomsg.h>
#include <sys/dcmd_all.h>
#include <sys/neutrino.h>
#if (R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH)
#error access() implementation requires *_OK and S_I*OTH equivalence
#endif
static int __access(const char *path, int amode, int oflag) {
int fd;
int mode, n;
struct _io_stat s;
struct stat r;
struct _client_info info;
// Only 1003.1a valid modes allowed
if((amode & (F_OK | R_OK | W_OK | X_OK)) != amode) {
errno = EINVAL;
return -1;
}
// get the stat info
s.type = _IO_STAT;
s.combine_len = sizeof s;
s.zero = 0;
if((fd = _connect(_NTO_SIDE_CHANNEL, path, 0, oflag | O_NONBLOCK | O_LARGEFILE | O_NOCTTY, SH_DENYNO, _IO_CONNECT_COMBINE, 0, 0, 0, 0, sizeof s, &s, sizeof r, &r, 0)) == -1) {
return -1;
}
// Use realids instead of effective
ConnectClientInfo(-1, &info, NGROUPS_MAX);
if(oflag & O_REALIDS) {
info.cred.euid = info.cred.ruid;
info.cred.egid = info.cred.rgid;
}
if(info.cred.euid == 0) {
// super-user always gets read-write access
// and execute access if any x bit is set
// and directory search access
mode = (S_ISDIR(r.st_mode) || (r.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) ? S_IROTH | S_IWOTH | S_IXOTH : S_IROTH | S_IWOTH;
} else if(info.cred.euid == r.st_uid) {
mode = r.st_mode >> 6;
} else if(info.cred.egid == r.st_gid) {
mode = r.st_mode >> 3;
} else {
for (n = 0; n < info.cred.ngroups && info.cred.grouplist[n] != r.st_gid; ++n)
;
mode = (n >= info.cred.ngroups) ? r.st_mode : r.st_mode >> 3;
}
mode &= R_OK | W_OK | X_OK;
if((mode | amode) != mode) {
close(fd);
errno = EACCES;
return -1;
}
// If not a directory, check mount flags
if(amode & (W_OK | X_OK)) {
int flags;
if(_devctl(fd, DCMD_ALL_GETMOUNTFLAGS, &flags, sizeof flags, 0) != EOK) {
// Doesn't support mount flags, so default to NOEXEC
flags = _MOUNT_NOEXEC;
}
// Check read-only file system
if((amode & W_OK) && (flags & _MOUNT_READONLY)) {
close(fd);
errno = EROFS;
return -1;
}
// Check mounted noexec
if(!S_ISDIR(r.st_mode) && (amode & X_OK) && (flags & _MOUNT_NOEXEC)) {
close(fd);
errno = EACCES;
return -1;
}
}
close(fd);
return 0;
}
int access(const char *path, int amode) {
return __access(path, amode, O_REALIDS);
}
int eaccess(const char *path, int amode) {
return __access(path, amode, 0);
}
__SRCVERSION("access.c $Rev: 153052 $");

41
lib/c/1/alarm.c Normal file
View File

@@ -0,0 +1,41 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <inttypes.h>
#include <sys/neutrino.h>
unsigned alarm(unsigned secs) {
struct _itimer i, o;
unsigned ret;
i.nsec = secs * (uint64_t)1000000000;
i.interval_nsec = 0;
if(TimerAlarm(CLOCK_REALTIME, &i, &o) == -1) return (unsigned)-1;
/* this call cannot return 0, unless the timer has fired */
ret = (unsigned)(o.nsec / (uint64_t)1000000000);
return (o.nsec && ret == 0) ? 1 : ret;
}
__SRCVERSION("alarm.c $Rev: 153052 $");

2
lib/c/1/arm/Makefile Normal file
View File

@@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

View File

@@ -0,0 +1 @@
include ../../../common.mk

View File

@@ -0,0 +1 @@
include ../../../common.mk

82
lib/c/1/arm/sigstub.S Normal file
View File

@@ -0,0 +1,82 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
/*
* WARNING WARNING WARNING - gdb uses a bytecode signature to sniff for signal handler
* frames.
*
* DON'T CHANGE THIS FILE without consulting with the gdb guys...
*
*/
/*
* sigstub.S
*
* int __signalstub (struct _sighandler_info *ss)
*/
#include <asmoff.def>
.text
.align 2
.extern SignalReturn
.global __signalstub
__signalstub:
/*
* Save r1-r12 in _sighandler_info->context.uc_mcontext.
* The kernel saves r0, sp, lr, pc and spsr.
*/
ldr lr, [r0, #SIGSTACK_CONTEXT]
add lr, lr, #UCONTEXT_CPU+4
stmia lr, {r1-r12}
/*
* Remember the _sighandler_info and uc_mcontext pointers
*/
mov r4, r0
mov r5, lr
/*
* Call handler(signo, siginfo_t *, ucontext_t *)
*/
ldr r0, [r4,#SIGSTACK_SIGNO]
add r1, r4, #SIGSTACK_SIGINFO
sub r2, lr, #UCONTEXT_CPU+4
mov lr, pc
ldr pc, [r4,#SIGSTACK_HANDLER]
/*
* Restore r1-r11 and call SignalReturn(_sighandler_info *)
*
* Note that SignalReturn trashes r0 and ip, which means that
* the kernel must restore r0, ip, sp, lr, pc and spsr.
*/
mov r0, r4
ldmia r5, {r1-r11}
#ifdef __PIC__
b SignalReturn(PLT)
#else
b SignalReturn
#endif
.type __signalstub,function
.size __signalstub,.-__signalstub

View File

@@ -0,0 +1 @@
include ../../../common.mk

View File

@@ -0,0 +1 @@
include ../../../common.mk

28
lib/c/1/cfgetispeed.c Normal file
View File

@@ -0,0 +1,28 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <termios.h>
speed_t cfgetispeed (const struct termios *termios_p)
{
return(termios_p->c_ispeed);
}
__SRCVERSION("cfgetispeed.c $Rev: 153052 $");

29
lib/c/1/cfgetospeed.c Normal file
View File

@@ -0,0 +1,29 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <termios.h>
speed_t cfgetospeed (termios_p)
const struct termios *termios_p;
{
return(termios_p->c_ospeed);
}
__SRCVERSION("cfgetospeed.c $Rev: 153052 $");

31
lib/c/1/cfsetispeed.c Normal file
View File

@@ -0,0 +1,31 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <termios.h>
int cfsetispeed (termios_p, speed)
struct termios *termios_p;
speed_t speed;
{
termios_p->c_ispeed = (speed == 0) ? termios_p->c_ospeed : speed;
return(0);
}
__SRCVERSION("cfsetispeed.c $Rev: 153052 $");

29
lib/c/1/cfsetospeed.c Normal file
View File

@@ -0,0 +1,29 @@
/*
* $QNXLicenseC:
* Copyright 2007, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*/
#include <termios.h>
int cfsetospeed ( struct termios *termios_p, speed_t speed)
{
termios_p->c_ospeed = speed;
return(0);
}
__SRCVERSION("cfsetospeed.c $Rev: 153052 $");

Some files were not shown because too many files have changed in this diff Show More